John Swinney, Scotland's education secretary, said there was a "realistic possibility" that students would be prevented from returning home in December "if we have a situation where the virus has not been controlled".
Speaking on the BBC Good Morning Scotland radio programme, the deputy first minister said the return of students at Christmas "without a doubt" depends on the coronavirus infection rate being reduced.
Asked if that meant students could be forced to remain in halls of residence, he said: "We want to avoid that at all possible cost because we want students to return home.
"But I have to be realistic that, if we have a situation where the virus has not been controlled, then we will have to look at other scenarios and other plans."
Mr Swinney added: "There is a lot of thinking and work going on within the Scottish government, with Universities Scotland, the institutions, with the National Union of Students, and also with the governments in England, Wales and Northern Ireland to try to make sure this can be undertaken as safely as possible.
"But there obviously is a risk that if the virus is not contained, then we may not be able to support the return of students to their homes.
"We want to avoid that but it is a realistic possibility."
Last month, Gavin Williamson, the UK education secretary, said students would be able to “spend Christmas with their loved ones if they choose to do so”.
But he said they may need to self-isolate at the end of the term to ensure it was safe for them to return home.
Dozens of universities have recorded outbreaks of coronavirus on campuses and in student halls, leaving thousands of students locked down in their rooms at the start of the academic year.
Register for free to continue reading
Registration is a free and easy way to support our truly independent journalism
By registering, you will also enjoy limited access to Premium articles, exclusive newsletters, commenting, and virtual events with our leading journalists
Already have an account? sign in
Join our new commenting forum
Join thought-provoking conversations, follow other Independent readers and see their replies