There has been some sort of injury caused to him, and he is suffering! You need to take it to the vet as soon as you can, or in the worst case scenario, you could lose it. Hope this helps, good luck.
I heard it was scent marking its probably marking its territory thats what I looked up cause my hamster doin da same thing