What Matlab code could be used to generate a random matrix whose $2 \times 2$ submatrices obtained from diagonal and anti-diagonal entries give a determinant of either $+1$ or $ -1$? The needed random matrix is an $n\times n$ but we should consider when constructing such matrix that its $2 \times 2$ submatrices obtained from diagonal and anti-diagonal entries give a determinant of either $+1$ or $ -1$. Please see the picture below to understand an example of such a matrix.
Thank you.

The way I see it.
Let $k$ be the number of diagonal "submatrices" ($k=4$ in your example). It means that the dimensions of your big matrix are $2k \times 2k$ or $(2k+1) \times (2k+1)$.
First select a range of variation for your entries, say $[-r,r]$.
Then generate an exhaustive list $L$ of all possible $2 \times 2$ matrices $M$ with entries in $[-r,r]$ and $\det(M)=\pm 1$. Let $\ell$ be the length of list $L$.
Then generate $k$ times ($k$ has been defined at the beginning) a random integer number $p \in [1,\ell]$, allowing to select in list $L$ (with possible repetition(s)), $k$ matrices $M$ that remain to be "installed" in your big matrix.
Remarks :
$$L=[L,M]$$
(with initialization "void list" $L=[ \ ]$) ending up in a $2 \times (2 \ell)$ array to which you will get access by steps of 2 units.
These two options are taken in the following Matlab program :