The replacement process migrates all of the attributes / classes from the old element to the new one. See the Directives Guide for an example.
Angular applies ID to the outermost span whilst the code explicitly applies ID manually to the hidden input checkbox. That results in duplicate unnecessary IDs which is invalid HTML.
Please see the following: https://code.angularjs.org/1.4.8/docs/api/ng/service/$compile
It says:
Angular applies ID to the outermost span whilst the code explicitly applies ID manually to the hidden input checkbox. That results in duplicate unnecessary IDs which is invalid HTML.