No, Ceuta was never part of Morocco.
Google tells me it depends. A large part of modern Morocco was unified in the late 8th century. The Portuguese conquered it in the early 14th, and the Spanish took it from them. Morocco in its current form was only a country in the mid 20th.
Similarly Gibraltar was taken in 1704, but modern Spain dates from 1804.
So, either you could say Ceuta was never Moroccan, and Gibraltar was never Spanish. Or you can argue that the Portuguese took Ceuta from Morocco and the British took Gibraltar from Spain.
Given that these places were conquered forcibly from the neighboring territory that now forms part of Spain and Morocco, there seems more of an argument for the latter, I would say.
All this does show the folly of going back as far as you want to decide what you "should" have as a country. As Putin has shown .you can generally find some part of history that gives the answer you want.