Anyone who shares a house with a dog will be aware that dreams are not an exclusively human activity, although of course we can only speculate as to what passes through the canine brain during rapid eye movement (REM) sleep. Other mammals, and even birds, also show signs of dreaming. Given the relationship between birds and the extinct dinosaurs, perhaps tyrannosaurs had their own very large dreams. Inconclusive evidence of dreaming in lizards has led to speculation that the origins of dreams might predate the evolutionary split between mammals, birds, and reptiles, but the truth may be more complex.
Experts on dragons disagree on their propensity to dream. J.R.R. Tolkien recounts Smaug's uneasy dream featuring an insignificantly sized warrior. In contrast, Ursula K. Le Guin reports; “The dragons do not dream. They are dreams.” Fire-breathing dragons being out of stock, and the Komodo species making troublesome research subjects, scientists from the Université Claude Bernard Lyon 1 tested the issue with Australian bearded dragons (Pogona vitticeps).
Paul-Antoine Libourel implanted electrodes in bearded dragon skulls and observed two different sorts of brain waves. One had a very low frequency indicative of deep sleep, while the other was much more like the signals produced when awake. Although Libourel reports in PLOS Biology that while the dragons' eyes did not twitch like those of a dreaming mammal, the brain waves were similar enough to those seen during REM sleep to suggest something similar was going on.
When the work was repeated with the much less excitingly named Argentine tegu (Salvator merianae), Libourel also witnessed two very different sleep states during the course of a night. Nevertheless, while the dragons showed brain waves that looked quite like REM and non-REM sleep in mammals, the tegu was different. In particular, neither of its sleep states resembled the brain waves produced while awake, in contrast to REM sleep.

As far back as the '60s, evidence of REM-like sleep was reported in lizards. However, most of these studies were done in ways that failed to convince the skeptics. A recent study pioneered sleep research on bearded dragons and reached similar conclusions to Libourel, but lacked a comparison in other reptiles.
Meanwhile, most similar studies on turtles and crocodiles showed no signs of REM-like sleep. Consequently, even with evidence of dream-like states in lizards, the evidence casts doubt on the idea that dreaming evolved before the family tree of land vertebrates split between reptiles, birds, and mammals.
It's possible then that dreaming is something that evolved several times, which would indicate it must be very useful, even if we do not understand why we need it. It's also possible that REM sleep evolved gradually, and the tegu reflects a previous stage that true dreamers, dragons included, have left behind.