How do I apply the value iteration algorithm when there are two goal states?
What you could do is to trigger environment termination when rat either:  


steps into the trap  
picks both cheese pieces  


The problem with such setup is that, when the rat picks a single piece, it would move one step to the side, and then it would come back to the same cheese spot so it would keep exploiting the same spot indefinitely. 

The solution to that would be to simply remove the cheese piece once the rat picks it up, so that it can't exploit it indefinitely. 

Sadly, another problem would arise which is partial observability: Markov property wouldn't be fulfilled because the current action wouldn't depend on the current state solely, it would be important whether cheese piece was picked before or not. 

The solution to that would be to make environment fully observable. You could accomplish that by expanding the amount of information about your current state. Before, only your position on the grid was important, but now you would also add state features that tell you whether cheese piece at specific position was picked or not. You would basically add a flag for each cheese piece that has value of 1 if piece was picked, or value of 0 if it wasn't. That way you could remove cheese piece it rat picks it, and you would still have full information. 

I believe this setup would work.