Hello and hope you are doing well.
The pain could be due to Balanitis, which is inflammation of the glans penis. It is usually occurs in uncircumcised men
, in whom the smegma collection along with discharge is likely to result in inflammation. This causes pain, discharge, itching, difficulty urinating and sometimes impotence. This is very common in diabetics.