Competition between Kondo and magnetic polaron states in Ce and Yb monopnictides