A federal judge ruled here for the first time on Thursday that the Bush administration had no basis for holding several of its long-term prisoners at Guantanamo Bay, Cuba, and he ordered that five of the Algerian natives go free. The question in the case was whether the men, who lived in Bosnia and had never fought or been near a battlefield, had plotted with al-Qaeda and were planning to fight in Afghanistan. In Thursday’s ruling, US District Judge Richard Leon, a Bush appointee, said the Government’s case was weak because it relied on only one unnamed witness who linked the men to Qaeda, he said. “This is a good day for the American justice system,” said Robert C Kirsch, part of a team of Boston lawyers. “They were swept up by mistake. This is remarkable because Judge Leon essentially told the Government, you don’t have a case and you never had a case against these men.”