Stochastic maximum principle with control-dependent terminal time and applications