Let $n\geq 3$, let $Z$ be the matrix of the cyclic shift (the companion matrix of $X^n-1$), and for $\mathbf{d}\in \mathbb{C}^n$ let
$\operatorname{diag}(\mathbf{d})$ be the diagonal matrix with $\mathbf{d}$ on the diagonal,
and $$M\_\mathbf{d}:=\operatorname{diag}(\mathbf{d})+Z+Z^2$$.


Notation: call a subset of $[n]:=\{1,\ldots,n\}$ separated if does not contain two (cyclically) adjacent elements, let $S\_j(n):=\{ M\in [n]\;:\, |M|=j\}$ denote the set of separated subsets of $[n]$ with $j$ elements.


For $n\leq 12$ the determinant is given by:
$$\det(M\_{\mathbf{d}})=\sigma\_n(d) +\sum\_{j=0}^{n-1} (-1)^{n-j-1} \sigma\_j(\mathbf{d})$$
where
$\sigma\_0(\mathbf{d})=\det(Z+Z^2)=\bigg\{\begin{array}{cr} 
 2 & \text{ for odd } n\\
 0 & \text{ for even } n\end{array}$


$\sigma\_1(\mathbf{v})=d\_1+\ldots+d\_n$, $\sigma\_n(\mathbf{v})=\prod\_{i=1} d\_i$, 
and for $2\leq j \leq n$
$$\sigma\_j(\mathbf{v})= \sum\_{(k\_1,\ldots,k\_j)\in S\_j(n)}\prod\_{i=1}^j d\_{k\_i}$$


Does the formula hold for all $n\geq 3$? 


Motivation: this (and related) determinants appear in a combinatorial problem arising in homological algebra, see [Classification of algebras of finite global dimension via determinants of certain 0-1-matrices](https://mathoverflow.net/questions/324534/classification-of-algebras-of-finite-global-dimension-via-determinants-of-certai/325637#325637)



Determinant of an "almost cyclic" matrix
For a length $n-1$ vector $a=(a\_1,\dots,a\_{n-1})$, define the $n$-by-$n$ tridiagonal matrix $T(a)$ with $1$'s on its main diagonal and subdiagonal and $a$ on its superdiagonal. The first two determinants are $\det T(\emptyset)=1$ and $\det T(a\_1)=1-a\_1$. By cofactor expansion on the last row we have $\det T(a\_1,\dots,a\_{n-1})=\det T(a\_1,\dots,a\_{n-2})-a\_{n-1}\det T(a\_1,\dots,a\_{n-3})$.


Define $\tilde S\_j(n)$ in a similar way but with linear (not cyclic) adjacency. Define also $\tilde \sigma\_j(a)=\sum\_{(k\_1,\ldots,k\_j)\in \tilde S\_j(n-1)}\prod\_{i=1}^j a\_{k\_i}$ for $0\le j\le n-1$. It's not hard to prove that $\det T(a\_1,\dots,a\_{n-1})=\sum\_{j=0}^{n-1} (-1)^j\tilde\sigma\_j(a)$ by showing both sides have the same initial conditions and satisfy the same recurrence.


I'll take $Z\_{ij}=\delta\_{i,j+1}$ (subscripts taken cyclically). $M$ is a lower triangular matrix $L$ plus three $1$'s in the upper right corner at $(1,n-1)$, $(1,n)$, and $(2,n)$.


The terms in the expansion of $\det M$ which do not contain any of these $1$'s contribute $\det(L)=\sigma\_n(d)$.


The terms which contain exactly one of the three $1$'s contribute $(-1)^{n-1}\det T(d\_2,\dots,d\_{n-1})$, $(-1)^nd\_n\det T(d\_2,\dots,d\_{n-2})$, and $(-1)^nd\_1\det T(d\_3,\dots,d\_{n-1})$ from the minors at $(1,n)$, $(1,n-1)$, and $(2,n)$ respectively.


The final terms contain the $1$'s at $(1,n-1)$ and $(2,n)$ and contribute $1$ to the determinant, since the minor is upper triangular with $1$'s on its diagonal.


It's straightforward to show that these five terms add up to your formula.


