I think that was the purpose why Roma sign back Ranieri, his task is to save Roma from relegation zone and Roma know Ranieri won't able to make Roma to get trophies. Gasperini is better than Ranieri, he can brought Atalanta to won Europa League, as we know Atalanta is just a mediocre team in Serie A, although it took a long time for Gasperini to get trophy.
Who knows Gasperini might able to bring a trophy for Roma.
If i remember correctly, Claudio Ranieri is a special advisor for Roma and not a coach. Let's also say he will be a safe haven in case something happens or a coach is fired, as has already happened.
Let's say that he now feels he's finished with his coaching career so this is the only solution.
Last season, Ranieri successfully revived AS Roma from a position quite close to the relegation zone. And I think if AS Roma had been in the top 10 before Ranieri arrived, they might have competed for the title or a Champions League spot. However, before Ranieri arrived, AS Roma were already quite close to the relegation zone. Returning AS Roma to the top 10 would have been an extraordinary achievement. But Ranieri went beyond that. He brought AS Roma close to a Champions League spot. And ultimately, AS Roma secured a Europa League spot. And that's quite an extraordinary achievement for Ranieri.
Regarding Gasperini, I don't doubt this coach's quality. However, we shouldn't expect much from his first season at AS Roma. There will still be adjustments and adaptations that usually take time. However, if Gasperini succeeds immediately from the start of the season, that would be commendable.
Ranieri actually retired last season. However, because he felt called to revive AS Roma, he canceled his retirement and decided to coach AS Roma until the end of the season. And he impressed everyone. And now he can retire from coaching, although he's still involved in football. He's only retired as a coach. And yes, as planned from the start, Ranieri will become an advisor to AS Roma. And yes, this is a good thing for Ranieri and the team.