I give you... Dune
Frank Herbert wanted a universe teeming with science... but few projectile weapons and no energy weapons. Oh, they're there, but they're not the 1950s style of everybody-has-a-gun there. How did he do it?
He created a MacGuffin: shields. At the time the first book was written absolutely nothing was known about how the shields worked beyond (if I recall correctly), they're dependence on the "Holtzmann Effect." This was the MacGuffin used by Herbert to rationalize why people with space ships fought with knives.
What he did was create a worldbuilding rule that had nothing to do with science or even practicality: shields stopped fast-moving objects and exploded with the force of a nuclear bomb if touched by a laser beam.
Why is using a MacGuffin important?
I've gotta disagree with @Alkahest's answer. Ships in space must have some way of dealing with collisions. Bits of dust and rock that are far more damaging than any bullet. This harks back to Larry Niven's General Products Hulls: his MacGuffin. Hulls so strong that they can withstand black holes (if I remember that story correctly). They're advertisted in-universe as being indestructible. That's not a bad thing to have for general commercial traffic and military use, right? In other words, a hull so easily damaged that a bullet or energy weapon could casually puncture it is a technological dichotomy. At least I think so. During the years of space exploration it's one thing to have trivially damagable hulls... but in regular practice? That harks back to a quote I really like from Ken Burn's The Civil War. Speaking about the first engagement between the Monitor and the Merrimack, the narrator says:
From the moment those two ships opened fire that Sunday morning, every other navy on earth was obsolete.
Wooden ships vs. modern destroyers. Apollo-era spacecraft vs. GP Hulls. Bullets and personal lasers (lots of energy to defend against in space) aren't a threat to the ship.
And to introduce a Frame Challenge: ships will never be a good place for meelee weapons
What a good sword (and notably a polearm) requires is space. A lot of space. Space to swing the blade, to parry an attack... space. We're back to having a technology dichotomy. If you want to use swords on a space ship, that means you have the space to use them. Have you ever seen the inside of a modern aircraft carrier?

Image courtesy Twelve Mile Circle
Or, more to the point, a submarine?

Image courtesy Quora
Efficiency demands pretty much not a single wasted cubic centimeter. Yes, there are rooms big enough (maybe the dining hall) to have an epic sword fight. But nowhere else. The only meelee weapon anyone could really use is a dagger. You need big, wasted-space space ships made, unusually, out of thin enough material that a bullet would slide right through. I just can't suspend my disbelief.
Which is why you need a MacGuffin
Science will never allow you to have a regularly space-faring civilization with spaceships damaged by (and crews threatened by) something as meaningless as a bullet. There are a lot of things that can project a piece of metal at those velocities and none of them are guns. Just think about your maintenance room. Of course, that would justify 3D printers for everything... to avoid drills, saws and lathes. But what's science more likely to do? Use rubber bullets and tasers.
There's no perfect answer here — that's the point of a MacGuffin. So what could you use to rationalize the use of meelee weapons in areas where they'll be difficult to use?
Spacesuits, like space ships, are puncture- and tear-resistant. That means blunt force is more desirable for combat than piercing. Could we ameliorate that by adding plates? Sure! That was done historically... but it didn't stop the use of swords and decreases agility, which is a big deal at Zero-G.
Richochet inside a ship won't threaten the ship, but it can threaten equipment and people, including your own people. This is as much a problem for the pirates as it is the ship's defenders.
Unless you subscribe to some Clarkean Magic, energy has weaknesses. It requires big batteries/power-generators and it does bad things to the surrounding air (a big deal in an enclosed environment). Having everyone pass out from lack of breathable oxygen really dampens a good fight. (I'll be honest with you, getting rid of energy weapons is the more difficult task. How do you get rid of tasers?)
But, as a parting note, you have bigger problems
How do you stop using concussion grenades? Outside the ship it's obvious they're useless, but inside the ship is another matter. No shrapnel threatening the hull, just an ear-blowing head-cracking bang! that renders everyone in the compartment senseless even if they're wearing puncture- and tear-resistant suits. I think it's not hard to justify using the proverbial cutlass over a Colt 1911. But why would anybody choose not to use a concussion grenade?
On top of this, let's look at Zero-G more closely. Have you thought about what it'd be like to swing a sword in Zero-G? Not pretty. Not pretty at all. So let's look at Philip Nowlan's Buck Rogers: Armageddon 2419 AD. In that story the MacGuffin was a material that, balanced against the wearer's weight, made them weightless to the point of on-planet Zero-G. Cool, right?! But that meant you couldn't use regular guns or they'd spin/push you around. Solution? Rocket guns. Zero recoil. Change the rocket head so that, rather than piercing its target, it has a stunning bang! on impact. No threat to the ship. Why would anybody use a sword?
In short, find your MacGuffin and don't explain anything. Not how it works. Not why you're using it. Nothing. It's just a fact (aka, a rule) of your world that justifies the use of meelee weapons and a vulgar hand gesture to anyone who thinks it's "unrealistic" — because there's no solution that a little thought can't rip apart.
Armor in my setting is mostly reminiscent of medieval armor; that is to say, reinforced cloth, chain mail, and plate.
– WolfpupWrites Mar 04 '24 at 19:26Doubly so with any weaponry that can defeat power armor; it would probably damage a fuel line or an important wire if it missed.
– WolfpupWrites Mar 04 '24 at 19:59