>>936609399The wiki article on it claims internal gestation has evolved over 150 separate times in vertebrates that we know of, so there must be some evolutionary advantage.
https://en.m.wikipedia.org/wiki/Viviparity#:~:text=(Eulamprus%20tympanum).-,Evolution,viviparity%20is%20a%20linear%20model.
It also mentions the “cold climate hypothesis”, where it was more likely to evolve in higher altitudes or latitudes because it helps keep the developing embryos warm.
Whatever the reason, the only rule in evolution is “whatever works”. That’s how we end up with weird shit like marsupials which are kind of half way between.