From the Lionel Messi wikipedia article (emphasis mine):
On 1 July 2021, Messi became a free agent after his contract expired, with negotiations on a new deal complicated due to financial issues at Barcelona. On 5 August, Barcelona announced that Lionel Messi would not be staying at the club, despite both of the parties reaching an agreement and were due to sign a contract that day. The club cited financial and structural obstacles posed by the La Liga regulations as a reason for Messi's departure.
I don't get what's going on here. If Messi and the club reached an agreement, what exactly stopped them from simply signing the contract? Is it possible to deduce the reason from the information that is publicly available?