The Secure Enclave is a separate CPU within the A7 (or later) that’s responsible for low-level cryptographic operations. It doesn’t run iOS or anything resembling iOS, but instead runs a modified L4 microkernel. L4 is intended to run as little code as possible in the kernel, which should theoretically make the system more secure by reducing the amount of potentially buggy code running with elevated privileges. The Secure Enclave uses a secure boot system to ensure that it the code it runs can’t be modified, and it uses encrypted memory to ensure that the rest of the system can’t read or tamper with its data. This effectively forms a little computer within the computer that’s difficult to attack.
Apple employs some very smart people to make this stuff as secure as possible.