wenti-09
step 1:Click to open System Preferences
Step 2: Click to open the battery, then click Options.

step3:Open the content indicated by the red box and red arrow
Note that after completing the settings according to the above steps, you need to turn on the power to use the external monitor with the cover closed.as shown:

Note that after completing the settings according to the above steps, if the power is not turned on, after closing the cover, the external monitor cannot display the picture, but a black screen
The second method:
Step 1: Download Amphetamine from the Apple App Store.
step2:After the installation is complete, open Amphetamine Move to Quick Preferences and check the second option 
step3:After clicking Indefinitely, the MacBook case can be connected to an external monitor without power supply.