A general explanation on the correlation of dark matter halo spin with the large-scale environment