Because scientists understand a LOT about how light and energy are produced, and we know a lot about gravity and physics. Most of science is not 'human centered'. By that I mean, we don't have to physically touch or hold something in order to understand how it works. For the sun, we make measurements of the kinds of light it produces, and with special instruments called spectroscopes we can examine how atoms in the sun are moving. We can very accurately measure the temperature of the sun, and the way different parts of it are heated.
To understand the inside of the sun is very hard even for astronomers. Much of what we know we have to estimate from the kinds of data we have and from a knowledge of basic physics. Recently, astronomers discovered that the sun actually 'rings' like a bell, and by studying the different kinds of ways that the sun's surface is vibrating, this lets us probe deep into the inside of the sun, much like earth quakes on the earth let us probe the inside of the earth. We never actually get to see a real picture of the inside of the sun. Then again, we don't really need one because we have lots of other information about what's going on there.
The way the sun rings, tells us that it is not a smooth ball of gas inside, but has several different layers. The top layer boils like a pot of mush but the deep insides don't move at all. In the deep inside regions, atoms have to be slammed together so fast that some of them fuse and release lots of energy. This energy powers the sun itself and gives it light. We don't actually see these reactions, but we know they must be happening because the center of the sun is so hot. If it wasn't so hot, there would be no light, and the sun would collapse under its own weight.
All answers are provided by Dr. Sten Odenwald (Raytheon STX) for the
NASA IMAGE/POETRY project.