I was looking at this problem, and I have a solution for a finite board with $2^n$ squares, that I want to extend to a countably infinite board.
Label the squares from $0$ to $2^n-1$. Consider the set of all squares with a $1$ at the $i$th position in their binary expansion. If the number of heads in the set is odd, let $p(i) = 2^i$, else $0$. Compute $X = \sum_{i = 0}^n p(i)$.
XOR the index of the Magic Square with your result, and flip the coin with the resulting index. Thus, when your friend enters the room, when he computes $X^\prime$, by the same approach, he will get the correct index.
When I try to extend this to an infinite board, I have trouble with defining parity. There are many functions that map $\{0, 1\}^\infty$ to $\{0, 1\}$, so it doesn't seem unreasonable that there is such a function that obeys one rule: flipping any bit changes the value. Is there?
And would this strategy still work on an infinite board, assuming your friend can examine infinite coins? (Pretty sure the devil wins when your friend must examine arbitrarily large, but finite number)
Pardon the abuses of notation; I suspect there's a more accurate way to write "all infinite bitstrings" than putting an $\infty$ up there.
There are such functions, but I'm not sure if one can actually construct one. To obtain such a function, note that $\{0,1\}$ with addition and multiplication is the field $\mathbb F_2$. Then $\mathbb F_2^{\mathbb N}$, the sets infinite bitstrings is a vector space over $\mathbb F_2$. The set $B' := \{e_n \mid n \in \mathbb N\}$ of the unit vectors $e_n = (0, \ldots, 0, 1, 0, \ldots)$ forms a linear independent subset. Choose a basis $B\supset B'$ of $\mathbb F_2^{\mathbb N}$. Define $f$ on the basis by $$ f\colon b \mapsto \begin{cases} 1, & b = e_n \text{ for some } n \in \mathbb N\\ 0, & b \in B\setminus B'\end{cases} $$ extend $f$ linearly to a $\mathbb F_2$-linear function $f \colon \mathbb F_2^{\mathbb N} \to \mathbb F_2$.
Then $f$ is as wished: Flipping the $n$-th bit corresponds to adding $e_n$ and for $x \in \mathbb F_2^{\mathbb N}$ we have $$ f(x + e_n) = f(x) + f(e_n) = f(x) + 1 = \begin{cases} 1, & f(x) = 0\\ 0, & f(x) = 1.\end{cases} $$