https://www.canva.com/learn/the-ultimate-guide-to-font-pairi...
You can also just do it because you want to. It's just as common in other mediums to see the opposite (sans headers and serif body text).
The origin of sans-serif typefaces was in advertising, e.g. in posters and product labels, so it was natural to adopt them for headings. In this context an advantage of sans-serif fonts it is that it is easy to change their weight, e.g. to make them bold or extra-bold, without this making them uglier.
With the passing to computer displays, which have much worse resolution than printed paper, this has changed, because sans-serif typefaces became preferred for body text, because they are less damaged by low-quality displays.
To preserve a higher contrast between body text and headings, with pages intended to be seen on digital displays it has become quite frequent to use this reverse combination, of sans-serif for the body text with a serif typeface for headings, which will be rendered at a higher quality even on bad displays.