Making a "spiritual successor" is legal, as long as none of the copyrighted material from the original is present. That means that the story, characters, names, etc from the original can't be in the spiritual successor.
However, making a direct sequel would be illegal. Ex: "Portal 3", "GTA 7", using characters from the original, even just naming objects in the same way or remaking locations from the original, etc.
Gameplay concepts can occasionally be patented (for instance, US5718632A) and you'll need to ensure that your "spiritual successor" doesn't violate any of those. You'll also need to make sure that your naming isn't close enough to the original to violate any trademarks.
But ultimately, it fine to build a game that feels similar as long as you're not violating any of the things mentioned above.
Here's an example: Yooka-Laylee is a spiritual successor to Banjo-Kazooie. However, it doesn't take anything from the original. No characters are the same. No locations are the same. No plot is the same. It's not a sequel, but obviously fans of the original can recognize enough similarity in the premise to understand its inspiration.