It’s not just ducks that do this seemingly weird activity, most birds, with the exception of parrots, do this. The short answer to why they do this is that they are taking a quick nap. The long answer is that birds, unlike humans, don’t have the promise of being safe from danger while they sleep. They constantly have to worry about predators, like cats and bigger birds. With this in mind, it makes sense that it is not safe for them to sleep for long periods of time in the same spot. Instead, they have adapted to sleep for very short periods of time throughout the day. This is when you will see them tucking their bill beneath their wing.
For birds like Mallards, they can sleep out in the open because they are usually in groups. When they are in these groups, not everyone sleeps at the same time, so at least some of them can keep watch. However, for birds like Northern Cardinals, they sleep in bushes and trees, where they are offered some protection from danger. The thing in common with both of these places is that this is where you will usually see these birds. From the bird’s point of view, this makes perfect sense.
Now that you know where and why birds do this, you may still be wondering why birds don’t just sleep with their heads forward. They mostly sleep all “tucked in” to preserve heat, energy, and to rest their necks. Just like when humans are cold, they try to get as small as they can so they lose significantly less body heat. So, no, that duck isn’t checking to make sure it put on deodorant this morning. It is simply taking a nap!