First of all, one needs to know its body needs to maintain its internal temperature, which is about 37° if I remember right. This is a process called homeostasis .
When you're sick, fever symptoms can occur, and your body heats up.
Now, if you're exposed to the sun too, you are causing a temperature elevation in your body.
More specifically, to answer to your secondary as to why staying in a hot interior is still better than direct exposition to sun, it's because your body temperature is regulated by contracting or dilating your external vessels (those who are close to the skin). When you are directly exposed to a heat source, the exposed zone is adapting by playing on dilatation or contraction (I can't remember which one for heat or cold) of the external vessels. Too much of this can cause malaise.
This is a part of human thermoregulation process.
Edit: As to references into the literature on heat exposure effects, there are quite a bit, here are some quotes :
Knochel 1974, review
-Heat exhaustion [...] due to predominant water depletion [...].
Symptoms (of hypertonic dehydration, ndlr) include fatigue, anxiety,
-Examining the response of resting normal subjects
to hyperthermia [...] showed that elevation of skin temperature [...]
was associated with a rise of arterial blood temperature [...] up to
a 125% increase of cardiac output [...].
See also Hales 1998 for related physiology that could lead to heat stroke.
I also agree that, as some comments pointed out, normal sunlight exposure shouldn't normally cause malaise, but I was referring to hot sunlight exposure, which, with conjunction with fever, is prone to get the body to abnormally high temperature.