The problem of the optimal control of a hybrid system (HS), the continuous motion of which alternates with discrete changes (switchings) in which the state space changes, is considered. The change in the dimension of the state space occurs, for example, when the number of controlled objects changes, which is typical, in particular, for the problems of controlling groups of moving objects of variable compositions. The switching times are not predefined. They are determined as a result of minimizing the functional, while processes with instantaneous multiple switchings are not excluded. The necessary conditions for the optimality of the control of such systems are proved. Due to the presence of instantaneous multiple switchings, these conditions differ from traditional ones, in particular, by the equations for auxiliary variables. The application of optimality conditions is demonstrated by an academic example.