In most undergraduate books, it is said that for second order phase transition Gibbs free energy and its first order derivatives are continuous at transition temperature. But the second order derivative are discontinuous at that temperature. What is the explanation behind it?
The definition of $n$-th order phase transition as a transition where $n$-th order derivatives of $G$ are discontinuous is the old Ehrenfest's classification which has been superseded by the modern classification where first-order phase transitions imply a discontinuity of the first-order derivatives, while any other non-analytic behavior of $G$ is classified as continuous (sometimes 2nd-order) phase transition. See for instance answers to related questions here on SE Physics.
The reason for such a change of terminology is historically rooted in the finding that the analytic solution of the Ising model in 2D displays a logarithmically diverging specific heat, which cannot be mathematically classified as a discontinuity.
One of the few continuous transitions which displays a real 2-nd order transition in the sense of Ehrenfest is the normal-superconducting transition in metals, where a real finite jump of specific heat is observed.