Hi there, thanks for writing to us on AskGuru.
It is illegal.
Your friend is not allowed to lock one room and sublet the remaining rooms while staying elsewhere. Doing so is a serious infringement of HDB's rules and regulations which may see HDB imposing a fine or even confiscating his/her flat
Hope this answers your question.