The problem was with the huge number of settings I was trying to save and the max_input_vars
limit was getting saturated.
I have now solved the issue by using jQuery to hide all the unused settings based on user input before submitting the settings form.