General framework to study the extremal phase transition of black holes