I was checking Robot C and I found that it allows you to create a preautonomous period, is it legal to use it in the competition in order to do some things with the LCD display?, for example, making a code which allows you to change some variables of the autonomous?

Yes, it is legal to use the pre-auton function for any purpose you would like in competition. pre-auton is a simple function that runs just after the main ROBOTC code starts. You must make sure to return from the function at some point before the autonomous or driver control periods of the match otherwise your robot may not be able to be controlled.