Your cactus has experienced a lack of light. Therefore it tried to find light by "exploring". This process is called etiolation.
Many plans experience this process if they are not able to get what they need.
Sadly there is not much you can do to fix it. Just give your plant a nice spot with enough light and time to recover.
~ You may be able to prune your cactus, your cactus will not be able to look the same as it did before though.