shihab-kol said:
I read in some books that as the sun approaches the end of the fusion process(the complete one) , it will expand and engulf some of the inner planets.
But why will it expand?
Whether the star would expand or contract in a particular stage of its evolution is heavily dependent on equation of state of the matter in its many layers. If layers are compositionally complex, you may need a supercomputer to accurately predict what would happen.
In the particular case of the main sequence -> red giant transition for a Sun, it's not that complex. The following happens.
As Sun burns hydrogen in its core, core very slowly becomes denser (because otherwise fusion rate would decline proportionally to the depletion of hydrogen, temperature and pressure would fall, while the gravity of the Sun's mass would stay the same, and Sun would be collapsing, which obviously isn't happening). The outer layers of the Sun do not become denser - they retain the same composition and remain in essentially the same balance of gravity versus gas pressure.
As Sun nears the end of its main sequence, core has contracted rather significantly compared to young Sun and now the gravity exerts larger pressure within it. Sun is about 40% more luminous now than it was ~9 billion years ago, and correspondingly its outer layers expanded a little, since now more energy is escaping from the inside.
Now when core burns its last percents of hydrogen, it shrinks A LOT, and quickly (within some thousands of years). The core now looks like a helium white dwarf (a very small, some 1% of Sun's diameter, very dense object) sitting inside the Sun. The gravity-induced pressure on the surface of the core ("surface of the core" being the boundary between 100% helium core and not-yet-100% helium plasma above it) is rising quickly, and the temperature of the gas has to rise to maintain the balance. Which it does by increasing the rate of fusion in the not-yet-100% helium layer adjacent to the core.
The outer layers of the Sun still retain the same composition as they were ~9 billion years ago. But insides get hotter and hotter, more and more energy needs to escape from the inside. Outer layers expand, this time significantly.