Correctional safety varies by setting. Overall, it's safe. It's still safe but less so in a setting where larger proportions of the patients are new to that location, withdrawing, and won't be at that location much longer.
So in general:
Jails are safe but the least safe, since people will not be there for a year, are new, and haven't had time to withdraw.
Intake / processing prisons are the next least safe, since people will likely not be there for 10 years, might now be detoxing after having been in jail but with access to their drugs, and might not have been receiving treatment in the jail or community.
Longer term prisons are the most safe. People there 20+ years aren't looking to fight with the psychiatrist and add another couple years to their sentence for assaulting them. They either have a recent exacerbation of a previously stable condition, have a new onset condition, or have been receiving treatment for years. You might be their doctor for 20+ years there, just like in the community.
There's also the levels of care for corrections. Generally there's the equivalent of outpatient (monthly or Q3, etc), IOP (day programs separate from the gen pop), and IP (think state hospital, qMonth notes but the unit is up to 60 patients). Just like non-corrections, the safest is OP and the most dangerous is IP.
Imo, these same patients are more dangerous when admitted to a community hospital during times free of incarceration than they are while incarcerated.
I've heard of many non-psychiatrists getting hurt all the time, just like in the community (techs, RNs, etc). The prison is generally too desperate for psychiatrists to not protect them to some degree. The inmates in general always know better than to attack a psychiatrist who is nice to them but might not shy away from attacking the CO who yells at them.