MacBook Pro Retina display only works with external display connected
Two days ago the Retina display of my MacBook Pro froze, including the cursor, while I was working without an external display. I first thought that it was a system crash, so I tried to restart, which also gave freezes during startup, so I had to restart repeatedly. Sometimes it just stayed like that, sometimes the screen faded to grey or became progressively darker and sometimes I had a freeze with the bottom half of the screen filled with horizontal coloured and white lines. Starting in Safe Mode (keeping Shift down during startup) did get me through, except that I had no longer access to a couple of fonts that I use very often, so I had to restart again anyway. I then figured out that I could get out of a freeze by closing the lid and opening it again, and that it was likely to be a display problem rather than a computer problem, because keyboard actions undertaken while the screen was frozen (such as opening a new window) turned out to have been executed the next time I opened the lid.
The screen then continued to work erratically: sometimes almost an hour without problems until the next freeze, sometimes no more than a few seconds, just enough to type my password and get to the Finder screen.
The next morning I could still work a few minutes, and then it froze pretty much immediately every time I opened the lid again. I decided to connect an external display to at least be able to continue working on that second screen. To my great surprise, as soon as I connected the external display, the problems with my Retina display disappeared completely and I could work normally. I can even switch off the second display and pull its wall plug, the internal display continues to function normally. It works with a connection via a Lightning port VGA adapter and with an HDMI cable. But as soon as I break the connection by removing the adapter or the cable, the Retina display freezes again.
What is going on? How do I solve this, so I can also use my laptop without having to connect an external display?
MacBook Pro (Retina, 13-inch,Early 2015), OS X El Capitan (10.11.6)