Why did Gaitonde kill himself when inspector Sartaj Singh enters the building to arrest him in Sacred Games?
In Sacred Games, Ganesh Gaitonde killed himself due to following reasons,
1) Ganesh Gaitonde had called Sartaj since he wanted to tell everything regarding the nuclear attack which is scheduled exactly after 25 days to ruin the Bombay city. He wanted to tell these major things to Sartaj because Gaitonde was thinking that there was nobody in this city who could be trusted, besides Dilbagh Singh (the father of Sartaj). Sartaj's father was very trustworthy person for Gaitonde because he helped Gaitonde when he was in prison. Sartaj was his son. So, he told to Sartaj on phone that there are only 25 days to save the city, so if possible save this city.
Pachhis din hai, bacha lena apne shehar ko
Lekin aap bhi apni baat sune bina pulis leke aa gaye.
But Sartaj brought the cops with him without properly listening to Gaitonde. So, Gaitonde could not tell full story to Sartaj.
Aapun ka kahani aadha reh gaya.
Anyhow Gaitonde wanted to save the city through reliable sources. He only relied on Sartaj. But Sartaj followed different way and wanted to arrest Ganesh Gaitonde.
Everyone betrayed Gaitonde, even Jojo also told Gaitonde at last that she was also with Guruji and Malcolm. She was cheating Gaitonde since 20 years.
2) Also, Gaitonde didn't know that Guruji sent him at Bombay to sacrifice Gaitonde's life for fulfilling his task to ruin the city.
At last, Gaitonde recalled the saying of Guruji that every big task requires sacrifice. The sacrifice of the dearest is always the purest. This world relies on stories. If there weren't sacrifices then there weren't stories. The meaning of Guruji was that if Gaitonde will not sacrifice then someone else will be sacrificed. So, there work won't be stopped.
Gaitonde had become very disturbed because even though he killed Guruji, he was feeling again and again that Guruji is there and preachning him these all things at morning, afternoon, evening.
So, due to all these reasons Gaitonde killed himself.
[Answer is given by watching and referring Season-1 (Episode - 1, Ashwathama) and Season-2 (Episode - 8, Radcliffe)]