High-level Spanish trips to Ceuta and Melilla are rare and a visit by Jose Luis Rodriguez Zapatero, the prime minister, in 2006, raised hackles in Morocco.
The last royal visit was 80 years ago.
Maria Teresa Fernandez de la Vega, Spain's deputy prime minister, said next week's royal visit was in response to requests by residents.
De la Vega added: "Relations with the kingdom of Morocco are extraordinarily good ... based on sincere affection and mutual respect."
However, Abbas el Fassi, the Moroccan prime minister, expressed surprise and "profound regret" at the royal visit.
"The government ... recalls that these two towns are an integral part of the territory of the Kingdom of Morocco and their return to the mother nation will come from direct negotiations between the Spanish neighbour", el Fassi's office said.
Spanish-Moroccan relations had hit a low point in 2002 when Morocco sent troops to the tiny disputed island of Perejil and Spain under Jose Maria Aznar, the former Spanish prime minister, sent special forces to oust them.
Tensions between the countries have since eased as Zapatero came to power and aligned his foreign policy closer to that of Moroccan ally France.
El Fassi and his conservative Istiqlal [Independence] party came to power in September 2007 with a nationalist agenda.
This includes the claims to the cities, which Morocco calls Sebta and Mellilia, and Spain's former colony of Western Sahara, as part of Morocco's "territorial integrity".
Spain took Melilla at the end of the 15th century and took over Ceuta from Portugal in the 17th century.