How should I mount my wall cabinet by this pipe
The same way it was, with it sticking through the inside of the cabinet, because it's a clean-out. If it's to a drum trap, you will need access to it in the future.