Let's take a stab at the case with 3 squares/coins.
When the second prisoner comes in she will say that the magic square is 1, 2, or 3 based only on the state of the 3 coins. There are 8 possible states for 3 coins, so whatever strategy is devised must partition the 8 end states into the 3 outcomes. Since 8 is not divisible by 3, that means 1 outcome will be assigned at most 2 states.
Those 2 states can only by reached by 6 possible input states (since each input state can only reach 3 output states - one for each possible coin flip). That means there are 2 remaining possible input states that cannot reach the given outcome. So for any possible strategy the jailer can choose the output with only 2 states and one of the 2 input states that cannot reach it to foil the strategy.
There are 2^n possible end states to partition into n outcomes. So there must be at least 1 outcome given by at most 2^n/n end states. If n is not a power of 2, then 2^n is not divisible by n, so there must be one outcome with strictly fewer than 2^n/n states, call it m. However that outcome can only be reached mn input states. Since m < 2^n/n, we have that mn < 2^n. That means there are input states which cannot reach the given outcome. So for any possible strategy the jailer can choose the outcome with fewest possible end states, and then an input state that cannot reach that end state making it impossible for the second prisoner to reach that outcome.
Let's take a stab at the case with 3 squares/coins. When the second prisoner comes in she will say that the magic square is 1, 2, or 3 based only on the state of the 3 coins. There are 8 possible states for 3 coins, so whatever strategy is devised must partition the 8 end states into the 3 outcomes. Since 8 is not divisible by 3, that means 1 outcome will be assigned at most 2 states. Those 2 states can only by reached by 6 possible input states (since each input state can only reach 3 output states - one for each possible coin flip). That means there are 2 remaining possible input states that cannot reach the given outcome. So for any possible strategy the jailer can choose the output with only 2 states and one of the 2 input states that cannot reach it to foil the strategy.