Westminster has effectively ruled out educating children held at the Dungavel asylum centre in local schools.
The first minister accused the SNP of opportunism
Immigration Minister Beverley Hughes said she wanted the "best possible education" provided for children inside the centre.
In a special debate in the Scottish Parliament, Scottish National Party leader John Swinney appealed to MSPs to follow their consciences and end the policy of detaining children.
The privately-run centre in South Lanarkshire, which can hold up to 150 asylum seekers, has caused controversy by holding children in the former prison for long periods with their parents.
Scotland's Communities Minister Margaret Curran said she had been in discussion with ministers at Westminster to implement the recommendations of an education inspector's report.
In a statement on the talks, Ms Hughes said: "These are children who are going to be removed from the UK very shortly.
"Are people really saying that bussing a child out of a centre every morning, accompanied by strangers because their parents couldn't accompany them, settling them in a school where they might be for a matter of days only to be deported, is actually doing something that's in the best interest of their children?"
It is understood that South Lanarkshire Council had been drawing up plans with the executive to educate Dungavel children in local schools on day release but that has effectively been vetoed by Westminster.
The Dungavel centre has proved controversial
An SNP motion in parliament called for "an end to the detention of children" at the Dungavel Immigration and Removal centre.
It also sought an end to "a system of detention of children at Dungavel which denies them access to social contact and to educational and other services in the local community".
Mr Swinney said the current situation contravened children's rights.
"It is a mark of national shame that in 2003, in one small part of Scotland,
those universal values are being denied.
"Today we have the opportunity to end that national shame and to say loud and clear that this parliament condemns the imprisonment of children in Dungavel and we demand an end today to this shameful practice."
He also urged First Minister Jack McConnell to take a stand against the "immoral imprisonment of children" and called for families to be asked to report to a police station or a social work department instead.
But Mr McConnell dismissed the SNP's stance, accusing them of using the issue of children as a political football.
"Any decision about their welfare or their education should be made not on the basis of an independent immigration policy for Scotland, or the winding up for political ends of this debate, but the interests of those children.
"If we don't put them first then we are abdicating the responsibilities in this parliament."
The Conservatives' deputy leader, Annabel Goldie, said that detaining children was "something which of necessity cannot be avoided".
She said either the SNP were in favour of no checks on asylum seekers or that they did not agree with children being detained alongside their parents.
John Swinney said Dungavel was a "national shame"
But Mr Swinney also questioned why ministers had not revealed details of the Westminster talks until the eve of the debate in the Scottish Parliament.
"We should have heard from ministers exactly what they were up to," he said.
In an impassioned speech, Scottish Socialist MSP Rosie Kane made clear her opposition to Dungavel.
She said: "Detention of innocent people is wrong. Dungavel and other
detention centres all over the UK are wrong.
"Innocent people are being kept in new family units and we have to oppose
that. We cannot shut up in this parliament."
After the debate, MSPs voted for an end to round-the-clock detention of children at Dungavel.
A Liberal Democrat call for youngsters to be educated at local schools while being held in the centre was passed by 71 votes to 33.
A mother and her three young children have been released from Dungavel while they fight their deportation order.
Bushra Sharif were told at an Immigration Appellation Authority hearing that they must stay with the housing campaigner, Robina Qureshi.
The family came to the UK last year after fleeing her husband, whom she claimed was violent and abusive.