Hona--Luisa Cohen--Fuentes and Euan Kidston claimed they were studying in the University of Edinburgh's Old College on Tuesday when they were "roughly seized" by staff and told: "We have someone really important coming here, we can't have the likes of you roaming around."
On being told that the building was closing, the students allege they were prevented from leaving by university staff who said they "could be any random scum off the street".
The female student also claims the member of staff told her: "I hope you get deported."
In her role as chancellor of the university, Anne carried out a series of engagements at the institution on Tuesday.
Mr Kidston, a third-year anthropology student, said: "I'm still in shock. We were quietly studying and had no idea the building was closing.
"There was no need for violence, we were happy to find somewhere else to study."
The pair allege they were then met by royalty protection officers and police in the building's quadrangle, and searched in front of other students.
They say they were detained by police for almost six hours at the city's St Leonard's police station.
Ms Cohen--Fuentes, an international student, said: "I was reading philosophy when I was assaulted in a building I assumed to be safe, before being put in a prison cell."
Responding to the allegations, a University of Edinburgh spokeswoman said: "At a time of heightened security in relation to the Chancellor's visit to the University, two students were escorted from Old College as they could not provide a satisfactory explanation for their presence in a part of the building that is a restricted area. "
Edinburgh University Students' Association (EUSA) trustee Mike Shaw said the incident represented a "disgusting breach of trust between the student body and their institution".
EUSA is supporting the students by submitting formal complaints against the university and Police Scotland, he said.
A Police Scotland spokesman said: "During a security check at an Edinburgh University venue two people were found within a restricted area and were subsequently detained. They were later released without charge."