Yes the Outer Space Treaty forbids weapons of mass destruction in space, and I think this may be the only weapon ever sent into space with the aim to damage enemy satellites, the Russian laser pistol / gun.
but that was in the Soyuz TMA and meant for self defense from wild animals on return to Earth, in case there is delay in picking them up - which happened once when the cosmonauts had to survive overnight in the cold Siberian conditions before they were picked up.
They now carry a regular pistol for this purpose.
The Apollo astronauts had a knife with them as part of their survival kit.
The outer space treaty also commits all the nations to peaceful co-operation while exploring space, and to render assistance to each other.
They can't for instance set up a military base on the Moon. And can't establish territories in space. So that reduces the need or desire to put weapons into space apart from these reasons of self defense against animals on return to Earth.
Another thing to bear in mind, a gun fired in space would be extremely hazardous likely to damage sensitive spacecraft components including life support and spacesuits. So I don't think we'll have astronauts carrying guns any time soon. The one in the Soyuz would only be used after return to Earth.
If we ever had war in space, which hopefully we never will, then any spacecraft with astronauts in, or any habitats unless buried many meters below the surface would be extremely vulnerable given that it is easy to build up relative delta vs of several kilometers per second, for large heavy objects far heavier than a bullet (and the fastest hyper velocity rifles are generally only a little over 1 km / sec). You'd just need to not brake at the right time and you could destroy the ISS or a habitat.
Indeed the Russians once came close to destroying their own space station through a mistake made while testing docking.
So if that can happen just by accident, obviously if we ever had any warfare in space, then all the humans in space would die soon after outbreak of hostilities.
During the cold war the US developed a weapon called Project Excalibur which would make laser x rays, to shoot down ballistic missiles. The plan was to explode a small nuclear device in space and then use solid rods to focus the x rays from the explosion on the ballistic missiles rising above the atmosphere. This was part of the strategic defence initiative.
The design wasn't actually using the nuclear weapon for mass destruction but rather to defend the US against mass destruction.
The question is - is it okay to put a weapon of mass destruction into orbit if the stated intention is not to use it for mass destruction? Would need to be a space lawyer to say I suppose but it does seem to breach the spirit of the treaty.
As a way around this they had the idea to launch on warning, so that if they detected incoming ballistic missiles it would be launched and then fire x-ray lasers from space to disable lots of the incoming missiles in one go. So then it wouldn't actually be stationed in space.
It was never actually completed, and the US loss interest in it at the end of the cold war.
Then as well as that, there's the 2007 Chinese anti-satellite missile test - which showed their ability to destroy one of their own satellites - however in the process it created a huge amount of "space junk" endangering other satellites in LEO.
Then there's the US X37 program. A mini space shuttle that can fly into space and return to Earth. Lightsail was launched with this, as a piggy back satellite along with other cubesats and other experiments.
There's been some suggestion it could be used for delivering weapons, or even for instance capturing other spacecraft from orbit.
But its specs, the huge amount of fuel needed to change orbit significantly in LEO so though it's maneuverable compared with most satellites - it's got severe limits in what it can do - and the fact that it is highly visible even from amateur telescopes so not capable of any form of stealthy action would seem to suggest that's not very likely.