(Scroll to the bottom for a tl;dr)
I completely disagree with the accepted answer. To start with, let's look at what the 5th edition Player's Handbook says about cantrips (page 201):
A cantrip is a spell that can be cast at will, without using a spell slot and without being prepared in advanced. Repeated practice has fixed the spell in the caster's mind and infused the caster with the magic needed to produce the effect over and over. A cantrip's spell level is 0.
(Emphasis mine) Here we see a cantrip is a type of spell. Earlier on the same page, where the PHB covers "What Is A Spell?", it says the following:
Some [spells] might yet lie recorded in crumbling spellbooks hidden in ancient ruins [...]
which establishes that there are spellbooks and also that they contain spells. In the Equipment section on page 150, the PHB describes a spellbook as costing 50gp, which, according to the Magic Items section on page 144, isn't very much:
[...] The value of magic is far beyond simple gold and should always be treated as such.
Later, on page 153, the PHB describes spellbooks thus:
Essential for wizards, a spellbook is a leather-bound tome with 100 blank vellum pages suitable for recording spells.
And that's about all the PHB has to say on spellbooks. We've got no indication of a Spellbook having any restrictions on the level of spell that it can contain.
Now let's look at the logic of the question's scenario.
A cantrip, according to the PHB, is a spell that casters know incredibly well due to repeated practice. Cantrips are not something a caster is born knowing; they have to learn it somehow. How a spellcaster came to be a spellcaster is completely glossed over by the PHB; it's more fun and interesting to leave that to a player's personal backstory for their character.
So, with the very sensible assumption that any cantrip known by a spellcaster had to be learned at one point or another, you've got to ask how it was learned? Was it taught by an instructor? Or did the spellcaster copy it from a spellbook in an arcane library somewhere, practicing it for years before mastery finally came? The answer is... it doesn't matter; the caster still had to learn it.
If a caster can learn a cantrip, ostensibly as the first bit of magic they ever learn, then so can a rogue or other mundane person. And if a cantrip is a spell, and spellbooks contain spells, then a spellbook can surely contain a cantrip.
It might not make much sense for an adventuring wizard, out saving the world, to waste space in his precious spellbook for cantrips, but it would certainly make sense to say they might have had a beginner's spellbook from their past, while still learning, or to say that the spellbook was stolen from a magical school somewhere.
Considering a blank spellbook is 50gp, and cantrips are incredibly low-level spells that require a ton of time to practice and learn, it's not outside the realm of possibility that a rogue could have stolen one and gotten away with it. A magic user or school would not expend much effort in stopping or tracking down someone who stole a spellbook with a cantrip or two in it.
In other words, I would say the backstory in the question is exactly how a spellcaster class like a Wizard would start learning and practicing magic... minus the stealing bit, perhaps.