When first coined, the expression ‘the ever after’ was a reference to Heaven.
When people were described as ‘happy ever after’ what was meant was that they were ‘happy in the ever after’.
This dates back to at least the 16th century, as in this piece by the French Protestant reformer Augustin Marlorat – A Catholike and Ecclesiasticall exposition of the Holy Gospell, 1570:
But after that Christe rose againe from death, then they were apointed ordinary teachers of the church: & in this respecte this honor pertained vnto the ever after
The first use of ‘happy ever after’ that I know of is from the same writer, a few years later, in A Catholike exposition vpon the Reuelation of Sainct John, 1574:
Moreouer John had commended faith sufficiently when he sayde, that the dead whiche dye in the Lord are happie ever after.
So, the 16th century ‘happy [in the] ever after’ meant eternal happiness in heaven, which migrated into the 18th century ‘happy ever after’ meaning ‘together forever in wedded bliss’.
– Cited from “https://www.phrases.org.uk/”