Asymptotically extremal polynomials with respect to varying weights and application to Sobolev orthogonality