He could have played till 2028 /2030. He had it in him to compete at international stage even now.
But I think what happened in the finals and the criticism of Argentina play style and his father's death made him hang the boots for good. Rightly so tbh. Younger players need time with the manager to build a team and they need atleast 4 years to try fill the gap Messi will leave behind
I still believe that this style of play was largely Scaloni's fault.
He could have rested Messi during the first half of the final; furthermore, he didn't trust young players like Nico Paz and set up the lineup far too timidly.
They weren't even a shadow of the 2022 Argentina side, and Messi had to carry the team single-handedly; otherwise, in my opinion, they could have easily beaten Spain.