This article by the LA Times has a good explanation which can be summed up with
Disney’s acquisition of Fox in 2019 changed that. Fox’s separate “X-Men” franchise is no more, and Marvel Studios is free to incorporate any of those characters into the MCU.
And to clarify your question it isn't Sony that owns the rights to the X-Men movies. It was Fox studios.