Shimano MTB levers with Shimano flat mount road disk brakes (hydraulic)
Yeah you can do that. Just make sure you use a new olive and insert pin.

I have seen it done on a self build frame of a guy as the wanted to integrate the brake as much as possible in the rear. You can follow the link and use and use a translator as it is in german.

https://www.mtb-news.de/news/2018/12/20/bike-der-woche-suit-1-eigenbau/