It can be a bacterial infection, but also found the following information:
Hamsters are susceptible to a severe diarrhoea known as Wet Tail, which always requires immediate veterinary treatment. It can be caused by rotten or mouldy food or bedding, or brought on by stress, such as over handling a new hamster. In mild cases of diarrhoea, fruit and vegetables should be withheld for a few days.