From first principles: Phase transition mechanisms of hexagonal Sc and Y under pressure