Shotguns in real life are very versatile weapons. There's a reason why most police departments use them as the long gun of choice. They can be used as breaching tools, with or without specialized breaching rounds. If they were represented accurately in video games, shotguns would be a sort of jack-of-all trades weapon, and also be the absolute master of some. They could be used to breach doors, and then immediately used to clear the room past the door. Then the player could step up to the window and engage targets out to 30 meters or so, which is medium range for most First-Person Shooter multiplayer maps. Loaded with rifled slugs, they could hit targets out to 100 meters, fairly long range for the aforementioned FPS maps, and be just as accurate as a rifle to that range. Slugs are so heavy and therefore have so much inertia that they render most body armor ineffective even though they won't outright penetrate. Rifled slugs will also penetrate a car door, both occupants inside, and then exit the other side of the car with enough energy left over to kill someone standing on the other side of the car. Again, this is because of mass and inertia. Flechette rounds basically a bundle of tiny nail-like projectiles would penetrate body armor even more easily, and cause fearsome wounds to boot.
The major drawbacks of shotguns besides the range limitations are related to the ammo. Because of how large a 12-gauge shell is, only so many can be carried on the user and in the weapon. The average pump-action or semi-automatic shotgun has a tubular magazine that runs under the barrel. Eight rounds plus one in the chamber is the normal max, and that's only if you have a longer barrel. Cut the weapon down to make it better in close quarters, and the ammo capacity is lowered. Very few modern shotguns have box magazines, and those that do can also only load seven to nine rounds. The AA-12 automatic combat shotgun is a rare exception drum magazines holding twenty or thirty-two rounds are available as well as the eight-round box magazines. The Armsel Striker, USAS-12, and Saiga-12 shotguns can also accept high-capacity drum magazines. All but the Saiga-12 are both rare and not very reliable. This ammo capacity drawback is fully represented in video games, and is in fact often exaggerated. It is impossible, for example, to use drum magazines with the AA-12 in both Modern Warfare 2 and 3.
Another factor in video games is Critical Existence Failure. In real life, the spread of shot makes it easier to score a hit on a target, compared to a rifle or pistol. A few pellets might have some effect on a combatant's ability to be fight, but in most games this would just leave the other player injured but unhindered by the hit. Some games mitigate this by having injuries affect the player in some way, or by ensuring a few pellets that hit the right area do enough additional damage to be a credible threat.
However, by far the biggest cause of this trope is exaggerated spread, often worsened by damage falloff. Spread for a shotgun varies depending on the barrel length, presence or type of choke added (added to force shot into a tighter spread before it leaves the barrel), the type of shot, etc. But even then, video games and other works tend to make it impossible to put most of the pellets into a man-sized target beyond 10 feet. It's even worse in some games, with damage per pellet drastically falling off over distance, or even vanishing outright at comically short distances.
Ultimately, shotguns are reliable, versatile weapons, effective in a number of different situations and environments. In video games, this versatility is undesirable due to the effect on game balance. So game developers make them effective only at extremely short range and with a significant spread to reduce the need for accuracy, preserving the rock-paper-scissors game balance they strive for.