Hanuman sided with Sugriva because Sugriva was the son of Surya (the Sun God), and Hanuman was also a son of Surya (born through Vayu to Anjana, but spiritually connected to Surya). This made Sugriva his Guru's son, creating a sacred obligation. In Indian tradition, a Guru's son is to be protected as one's own brother. The family relationship (Guru-shishya parampara) took precedence over other considerations.