Fasting is compulsory because it was ordered in the Quran for those who are mentally and physically fit, past the age of puberty, in a settled situation (not travelling), and are sure fasting is unlikely to cause real physical or mental injury.
READ ALSO: What are the Virtues of Ramadan?
Narrated Sahl: The Prophet said, “There is a gate in Paradise called Ar-Raiyan, and those who observe fasts will enter through it on the Day of Resurrection and none except them will enter through it. It will be said, ‘Where are those who used to observe fasts?’ They will get up, and none except them will enter through it. After their entry the gate will be closed and nobody will enter through it.” (Sahih Bukhari, Volume 3, Book 31, Number 120)