Ferrari is a whole another thing, they are the biggest team in world of sports, one of the biggest, they are like Los Angeles lakers or Real Madrid. So when you are not doing good there, the pressure is much higher than what you are facing at Mercedes. Plus, he won so much with Mercedes, so if he did badly there, nobody would bat an eye and they would just thank him for what he has done for the team so far, even if he was bad.
But at Ferrari, he did nothing, and that means he is expected to be worth it, Carlos Sainz did alright, nothing amazing, never won a title, but he was good enough, so if they sent him away to Williams and got Hamilton then there must be a reason for it and we need to see that reason at least.
Hamilton is one of the greatest drivers in F1 history with 7 world championships. For an iconic brand like Ferrari, the presence of a star like Hamilton will be a great advantage both in terms of sporting success and marketing. Ferrari has not had a drivers' champion for a long time.
Hamilton is a driver who knows how to win championships and can manage a race under pressure. I think they believe that Hamilton's experience can take Ferrari back to the top. I think Sainz was very good, but the Ferrari management saw the experience that Hamilton would bring as more valuable. Ferrari sees Hamilton as an investment, not only to increase success on the track, but also to increase visibility off the track.