Speculative fiction is the ultimate "what if?" question, taken to extremes. It feels like fanfiction, in spirit, because the author takes an event or a place or a historical figure (usually) and then twists their story around a bit.
For example: Mistress Shakespeare by Karen Harper is a book that hinges on a tiny signature in an old marriage register in Warwickshire, England. William Shakespeare married Anne Hathaway. Their marriage is recorded in a church. But strangely, in another church in a nearby town, the day before Shakespeare married Anne, there's a record of a marriage license or a wedding intended to take place between William Shakespeare and Anne Whateley. We know that he married Anne Hathaway, but who the hell was Anne Whateley? That's the question that Karen Harper attempts to answer. Nobody knows who Anne Whateley was, so her character and storyline are basically all fictional, but it's fitted in between the knowledge we have about what William Shakespeare was doing.
The Constant Princess by Philippa Gregory is another of what I would call speculative. It's about Katherine of Aragon when she was married to Henry VIII's brother Arthur. We know that much later on, when Henry was trying to annul their marriage, that he questioned whether Katherine and Arthur had consummated their marriage. Katherine swore that she was a virgin. In this book, though, Katherine and Arthur get busy before he dies and when she marries Henry years later, Katherine decides to keep quiet about it.