Your second idea is correct. The first "dream" is a transitive verb, the second "dream" is a noun. Interestingly, for some reason the phrase "to dream a dream"--and variations on it, like "I dreamed a dream"--are actually quite common. "I dreamed a dream" is almost as common as "I had a dream." Something about the repetition is pleasing.
"I Dreamed a Dream" is actually a song title from the musical "Les Miserables."