A combination of diplomatic pressures and security considerations forced Morocco's King Hassan II to abandon plans to hold national celebrations in the disputed territory of Western Sahara, according to western analysts here.

The festivities had been scheduled to culminate today with a colorful "oath of allegiance" ceremony that would have brought the king and hundreds of Moroccan tribal leaders to the Saharan capital of La'youn for the first time since the town came under Moroccan rule 10 years ago. In a last-minute switch after weeks of preparations, the festivities took place in Marrakech instead.

The change of plans represents a setback to King Hassan's hopes of securing international recognition for Moroccan rule over Western Sahara, where his Army has been involved in a costly guerrilla war with the Algerian-backed Polisario Front.

Independent western analysts say that Morocco has gained the upper hand militarily thanks to a successful strategy of building and defending sand walls in the desert. But the Polisario Front has scored a political success by winning diplomatic recognition from 61 countries for its Sahrawi Arab Democratic Republic.

Even if Hassan goes ahead with his plans to visit the territory over the next few days, the political symbolism that would have been associated with holding the annual oath-of-allegiance ceremonies in Western Sahara has been lost.

The change of plans has saved the Reagan administration from what would have been a sensitive diplomatic dilemma in deciding whether to be represented at ceremonies held by Morocco in Western Sahara. While the United States recognizes Moroccan administration over the region, which was formerly under Spanish occupation, it has not formally recognized Moroccan sovereignty.

A high-level team of American guests at this weekend's ceremonies included outgoing U.N. ambassador Jeane J. Kirkpatrick and Ambassador-at-Large Vernon A. Walters who has been nominated to replace her, as well as U.S. Ambassador to Morocco Joseph V. Reed.

Some western officials here speculated that the possibility of a boycott of the planned ceremonies in La'youn by the diplomatic corps might have been one of the reasons for the switch of sites. Others said security considerations also could have played a role.

A further consideration, according to some analysts, could have been the delicate stage of negotiations with neighboring Algeria on Western Sahara. Last week, Algerian President Chadli Benjedid sounded a conciliatory note toward Morocco in a speech by offering to hold formal talks on the Western Sahara issue without naming the Polisario as an essential participant.