I just had this problem occur on a 1.12 world in survival mode. The bed was underground (at y=10 if that helps) and was in a 3x3x3 cube dug out. There were two blocks covering the bed one block above the bed. I've included an example of what I am talking about.
I wrote a command for anyone who would like to test this bug to check if it still exists. Run the following command:
This will summon a villager who sells one emerald for one diamond. You can easily grab a stack of emeralds and test the bug. I hope this helps!