Duncan went to live with the Fremen in Stilgar's sietch before the Atreides first arrived on Arrakis. When the Harkonnen attacked, Idaho had already spent some time with the Fremen and came to know and respect them.
I don't have my book handy, but I don't think Herbert gives any dates for how long the Atreides are on Arrakis before the Harkonnen attack. We can only assume it was long enough for Idaho to have formed enough of an opinion about them to be so scornful about the museum Fremen.
Relevant passages from the book, courtesy of user KHW:
“Where’s Duncan Idaho?” Paul asked. “Isn’t he supposed to be teaching me weaponry?”
“Duncan’s gone to lead the second wave onto Arrakis,” Halleck said.
And, slightly later
“We’re negotiating with the Fremen right now,” Paul said.
“I sent a mission headed by Duncan Idaho,” the Duke said. “A proud and ruthless man, Duncan, but fond of the truth. I think the Fremen will admire him. If we’re lucky, they may judge us by him: Duncan, the moral.”
And, again, showing Stilgar knows him pretty well, just after the famous spitting scene
The Fremen looked at Idaho, said: “You measured well in my sietch, Duncan Idaho. Is there a bond on your allegiance to your Duke?”
“He’s asking me to enlist with him, Sire,” Idaho said.
“Would he accept a dual allegiance?” Leto asked.
“You wish me to go with him, Sire?”
“I wish you to make your own decision in the matter,” Leto said, and he could not keep the urgency out of his voice.
Idaho studied the Fremen. "Would you have me under these conditions, Stilgar? There'd be times when I'd have to return to serve my Duke."
"You fight well and you did your best for our friend," Stilgar said.