I wonder how the bitcoin protocol judge illegal transactions. As they say, the miner will look throughout the public ledger to make sure the transaction is alright. There are thousands of transactions in each block, if the miner has to check throughout the public ledger for each transaction, this would be very inefficient.
There are valid inputs and valid (because authorized by a signature of a private key) outputs. There is no need to check the whole public ledger (blockchain). If an address had no valid (like illegal) input, there will be a balance of 0. If the address had a valid input, which already was confirmed by the network, it can be spent by signing with the private key.