A bench of justices Umanath Singh and Mahendra Dayal passed the order while hearing a public interest litigation (PIL) filed by lawyer Moti Lal Yadav.
The petitioner contended that rallies based on castes were against the constitution and threatened to vitiate social harmony in the country's most populous state.
The court also issued notices to the central and state governments, the Election Commission, Samajwadi Party (SP), Bahujan Samaj Party (BSP), Bharatiya Janata Party (BJP) and Congress, making them party to the litigation.
In his petition, Yadav had brought to the notice of the court that every party in the state was vying to score brownie points by holding caste- based conventions and rallies.
In the last few months, the BSP had held 'Brahman Sammelans' in four places, with the biggest show of strength held in the state capital. That rally was addressed by party chief Mayawati on Sunday.
The ruling SP too recently held a similar Brahman convention and a Muslim rally which was addressed by party chief Mulayam Singh Yadav and Chief Minister Akhilesh Yadav.
Reacting to the court's order, BJP state spokesman Vijay Bahadur Pathak said his party welcomed the judicial intervention.
"The BJP has always been opposed to such rallies and I am happy that the high court has taken a firm and timely stand on the issue," he said.
Pradip Mathur, chief of the Congress legislature party in the assembly, also welcomed the court order.
He said both the SP and BSP were involved in caste politics to hide their failures.
"We as a party have never indulged in such politics and we are happy at the ban," he added.
SP and BSP leaders said they would react after going through the court order.
Photos: Abhishek Bachchan and Farah Khan at Boman Irani's birthday bash
Spotted: Shah Rukh Khan at Morani's bungalow in Mumbai
Spotted: Sonam Kapoor and sister Rhea at Mumbai airport
Photos: Ranveer Singh, Vaani Kapoor get 'Befikre' on 'Super Dancer'
In pictures: 12 child artistes who turned into beautiful divas