This story comes from the Italian chronicler Salimbene di Adam of Parma. He says that Frederick:
“...wanted to discover what language a child would use when he grew up if he had never heard. Anyone speak. Therefore, he placed some infants in the care of wet-nurses, commanding them to bathe and suckle the children, but by no means ever to speak to or fondle them. For he wanted to discover whether they would speak Hebrew, the first language, or Greek, Latin, Arabic, or the language of their parents. But he laboured in vain, because all of the infants died. For they cannot live without the praise, fondling, playfulness, and happy expressions of their nurses.” (Salimbene di Adam, trans. Baird, pg. 352)
This is one of Frederick’s “idiosyncrasies” according to Salimbene - among the others are that he cut off a notaries thumb for spelling his name wrong, that he tried to prove there was no life after death, and that he disembowelled two men to see how they had digested a meal. Salimbene could have reported more things but “reporting so many of the Emperor’s foolish notions is tedious to me.” (Baird, pg. 356)
But we should remember that Salimbene was extremely hostile to Frederick, and although his chronicle is full of interesting events, he was hardly an historian and pretty much everything he writes should be taken with a giant handful of salt. Frederick's modern biographer David Abulafia calls Salimbene a “shameless gossip” (Abulafia, pg. 251) and “foul-tongued” and says that he spread “preposterous stories...It is highly unlikely that Frederick indulged his scientific interests this way.” (Abulafia pg. 260)
The same story is told by Herodotus about the Egyptian pharaoh Psamtik I, and it's just as believable in Herodotus as it is in Salimbene. So, in brief, Frederick didn't really do this; he had extremely harsh critics for all the real things that he did, and if he did stuff like this on top of everything else, we definitely would have heard about if from other, more neutral sources.
Sources:
David Abulafia, Frederick II: A Medieval Emperor (Oxford University Press, 1992)
The Chronicle of Salimbene de Adam ed. J.L. Baird, G. Baglivi & J.R. Kane (Medieval & Renaissance Texts & Studies, 1986)