Dear User,
In carnot engine, the system is insulated i.e. q=0, but, the gas continues to expand or compress with the lost or gain of internal energy. This leads to the cooling or heating of the gas and the entropy remains unchanged. This is how it maintains reversible process.