In this paper, we propose the design and implementation of spherical magnetic joint (SMJ)-based gait generation for the inverted locomotion of multi-legged robots. A spherical permanent magnet was selected to generate a consistent attractive force, enabling the robot to perform inverted locomotion under steel structures. Additionally, the robot’s foot tip was designed as a balljoint mechanism, providing flexibility in foot placement at any angle between the tip and surface. We also introduced an adjustable sleeve mechanism to detach the foot tip during locomotion by creating a fulcrum during the tilt and pull steps. This mechanism effectively reduced the reaction force based on the sleeve diameter. The experimental results showed a 46% decrease in the present load when using the adjustable sleeve mechanism compared to direct pulling. For inverted locomotion, a quadruped robot and a hexapod robot, which represent the predominant type of multi-legged robots, were constructed. We integrated the SMJ and adjustable sleeve into both robots, enabling them to perform inverted locomotion with various gaits such as crawling, trotting, square, and tripod gaits. Our analysis examined the characteristics of each gait in terms of velocity and stability, thereby confirming the versatility of the proposed SMJ, which can be applied to different types of legged robots.