There is nothing stopping you from doing that, as far as I can see. Immigration would anyway be in BKK, only difference is arrivals or domestic transit immigration (which would also allow you to leave afterwards). On arrival to your destination, you would have to head to the carousel for International instead of Domestic arrivals (different hall) to retrieve your luggage.
I found this link that explains the procedure (scroll down to Arrival Procedure for CIQ:
https://phuket.airportthai.co.th/ser..._Procedure_HKT
Hope that helps.