It sounds like your budgies are having night frights, this occurs when something startles them and wakens them during the night. Because it is dark and they do not see well in the dark they get spooked and begin flying. This can result in injury to the birds. Your actions are correct in turning on the lights and letting them calm down. You can provide a night light near their cage so if they do awaken they have enough light to be able to see and that will help. If this is happening frequently try to figure out what may be spooking them, could be a sudden noise, a shadow, if they are near a window could be a passing vehicle etc.