Does a SIM card consist of only Flash memory or is there a microprocessor inside as well?
Even "simple" memory cards like SD, CF, MMC... must have processors inside them because you don't access the memory chips directly. Each memory chip is different in number of pins, address bus width, data bus width, access protocol... so the processor will create a common interface for communicating with external devices.
In case of SIM card there must be a microcontroller in the SIM card to process data, because the purpose of the SIM is to prevent the authentication key from being read. The phone never knows what key the SIM is currently holding. Only the mobile network operator and the SIM know that.
The phone just gives some data to the SIM and the SIM's processor will return back the encrypted data based on the key after some cryptography algorithm. That encrypted data will be sent back to the network operator, who will use the same algorithm to generate the encrypted data from the key in their database. If the two piece of data match, the authentication ends successfully.
More information about the authentication process can be found here