iPhone and iPad lock while playing videos over Airplay
I have the hdmi adapter and I think iOS handles that the same way as air play does.
Some apps like Amazon Video or the movies app have a good support for AirPlay. I can lock my iPhone and it will go on. But the last time I checked YouTube it didn't had the good support, it only mirrored the screen.
I think this is a problem of the app you are using.