The BBC understands that routine testing was done before migrants moved on to the vessel, moored in Dorset.
But test results showing traces of the bacteria came back only after migrants had moved to the barge.
The Home Office said the 39 migrants living aboard had been disembarked while assessments are carried out.
Legionella is the bacteria that can cause Legionnaires disease – a type of pneumonia.
The BBC has been told that while migrants have used the vessel’s water supply, none have so far showed symptoms, but have been removed from the barge as a precaution.
News that migrants were brought on board before the results of the UK Health Security Agency test came back will fuel criticism from campaigners and refugee charities that have opposed the use of the Bibby Stockholm.
The vessel – moored at Portland Port on the Dorset south coast – is part of the government’s plan to “stop the boats” and deter Channel crossings by migrants.
But the initiative had already suffered a shaky start after delays over safety concerns and legal challenges had frustrated ministers’ attempts to ramp up the numbers of people boarding the barge.
The government eventually plans to house up to 500 men aged 18-65 on Bibby Stockholm while they await the outcome of asylum applications.
The BBC understands the UK Health and Security Agency has recommended further testing of the water supply.
Another test has been done since the bacteria were found, and it is expected that migrants will be moved back only if and when the water supply is all clear of contamination.
It is not yet clear where those disembarking will be moved to temporarily.
It would be funny were it not so serious — Home Secretary Suella Braverman, the Home Office and Prime Minister Rishi Sunak.
Government sources have said they are complying with the UKHSA guidance and have gone “above and beyond” what has been recommended by removing people from the barge temporarily.
A Home Office spokesman said: “No individuals on board have presented with symptoms of Legionnaires’, and asylum seekers are being provided with appropriate advice and support.
“The samples taken relate only to the water system on the vessel itself and therefore carry no direct risk indication for the wider community of Portland nor do they relate to fresh water entering the vessel. Legionnaires’ disease does not spread from person to person.”
Legionella bacteria can cause a serious infection called Legionnaires’ disease.
The bacteria are normally found in rivers and lakes, but can also make their home – and grow in large numbers – inside water tanks and plumbing systems.
This becomes a problem when people breathe in infected water and the bacteria get into the lungs.
Something like a shower that creates a mist of water carrying the Legionella bacteria would pose a risk.
Once in the lungs, the bacteria lead to pneumonia and symptoms can include a cough, shortness of breath and a fever.
People infected will need antibiotics and in more severe cases oxygen support or even machines to help them breathe.