If a student under the age of twenty-one years is allowed to enroll in any common school outside the school district within which the student resides or a school district of which the student is considered to be a resident for attendance purposes by operation of law, the student's attendance shall be credited to the nonresident school district of enrollment for state apportionment and all other purposes.