This could be Yamato Takeru
A million years later, the Death Star Yomi is approaching the Onam System once again. Tsukuyomi, the master of Yomi, plans to take this opportunity to realize his dream of ruling the entire universe. He is desperate for the last stone containing Yamatano Orochi. If Tsukuyomi can get hold of this stone, Yamatano Orochi will return to life and its power will become his. Tsukuyomi needs Sky Warrior Susanoo to capture the stone, and sends 8 Sky Soldiers to get Susanoo back. But it is too late. Susanoo no longer belongs to Tsukuyomi. It belongs to Takeru, a 13-year-old boy from Earth, who happened to discover the buried robot Susanoo and woke it from its million-year-long sleep. Takeru becomes involved in the battle against the Sky Soldiers and their evil master, Tsukuyomi. Susanoo stands up to protect his friends and their planet.
The opening doesn't show him summoning the robot, but you can see the flute (more an ocarina) in his hands, and the sword later in.
Ah, and it is an ocarina:
Tamanoo is initially piloted by Amatsumi but after he is killed by Kiriomi, Yamato's new friend Kaon tries to pilot it. Even though Amatsumi was dead, Tamanoo is still shrouded in his evil presence. Only through Yamato playing his ocarina is the evil presence destroyed and Kaon is able to pilot it.
You can see Yamato using it early into the second episode:
I found it by searching for anime boy summons robot with flute, which led me to a Reddit query where it was the answer, then I researched further details.