Bandgap-assisted quantum control of topological edge states in a cavity