Clothes can be washed safely in a dishwasher if you place the clothes on the top rack away from the heating element.
When I lived in an apartment before and didn't have a washing machine but only a dishwasher I would place my clothes on the top rack in the dishwasher and the dishwasher cleaned the clothes just fine.
A washing machine will clean your clothes much better than a dishwasher but if you only have a dishwasher then the dishwasher will clean the clothes much easier and better than hand washing them.
You can also buy racks for your dishwasher to wash hats and other clothing but I just laid my clothes on the top rack of the dishwasher to wash them.
I would then add some laundry detergent powder to the dishwasher soap dispenser where the dishwasher detergent would go.