Beginning at the wiki, which, while not a reliable source by itself actually provides a source:
The giant baby head came, according to Dan Povenmire, "one board panel drawn by Mike Diederich and one of our directors, Rob Hughes thought it was hilarious and made a whole bit about it. Now it shows up all the time."[1]
This link goes to a page on tampabay.com, which unfortunately leads to a 404 now. However, contrary to what @JohnP said in their answer, I was able to find the link on the Web Archive, at a crawl in 2009.
The relevant portion:
One last question: What is with the giant floating baby head? (It's shown up in several episodes). We like it a lot when Candace says, "What does that even mean?"
Povenmire: That came from one board panel drawn by Mike Diederich and one of our directors, Rob Hughes thought it was hilarious and made a whole bit about it. Now it shows up all the time.
Marsh: We try not to think too much about the floating baby head . . . It makes us laugh, 'nuff said.
In universe, nobody knows exactly where it's from. The wiki is actually very helpful and provides a transcript of the entire episode, for every episode as far as I can tell:
Candace: Phineas! When Mom sees that you've built a haunted house in the backyard with werewolves and vampires and a Giant Floating Baby Head? What's that even about?
[...]
Phineas: That was a great day, Ferb. What did you think the scariest thing was?
Ferb: Definitely the Giant Floating Baby Head.
Phineas: Yeah...
(The ending of the Phineas and Ferb Theme plays.)
Phineas: Yeah, where did that come from?! (Ferb shrugs) Hm.
(The theme continues.)
"One Good Scare Ought To Do It!"
Phineas: We spent a day fighting pharmaceutical zombies,
Would've solved cold-fusion but did fashion instead.
We met Klimpaloon and Meap and the Lake Nose Monster
Phineas, Candace, and Ferb: But we're still baffled by the Giant Floating Baby Head.
"Last Day Of Summer"
My personal theory, though, is that the baby head came from another dimension. We see a whole dimension of baby heads when Phineas, Ferb, Dr. Doofenshmirtz, Perry, Candace, and a whole bunch of evil robots are dimension hopping. At 0:50 in this video, we can see a whole bunch of similar baby heads:
So it would seem that the baby heads came from another dimension and somehow ended up in our normal dimension, or it's somehow magically attracted to Phineas & Ferb's projects... anyway, it appears to come from the baby head dimension.