The Convent was created in A.D. 1748 by Barbara of Portugal, Queen of Spain. She wanted to create a school for girls of noble birth and a retirement home for herself.
Although the Queen died before her husband, Ferdinand VI, they are both buried in a tomb within this church. Ferdinand was very much in love with his wife, and I imagine he didn’t want to be parted from her. He is one of the few kings who is entombed outside of El Escorial.