$\color{Green}{\text{Lemma}}$:
- For every odd prime number $p$;
and for every positive integer $\alpha$;
the multiplicative group $\mathbb{Z}_{p^{\alpha}}^*$;
is
a cyclic group of order
$\phi(p^{\alpha})= (p-1)p^{\alpha-1}$.
In other words:
$$
\big(
\mathbb{Z}_{p^{\alpha}}^*
\ , \times
\big)
\equiv
\big(
\mathbb{Z}_{(p-1)p^{\alpha-1}}
\ , +
\big)
.
$$
- For $\color{Red}{p=2}$;
and for every positive integer $\color{Red}{3 \leq \alpha}$;
the multiplicative group $\mathbb{Z}_{2^{\alpha}}^*$;
is
the direct sum of $\mathbb{Z}_2$ and
a cyclic group of order
$\color{Red}{\dfrac{1}{2}}\phi(2^{\alpha})= \color{Red}{2^{\alpha-2}}$.
In other words:
$$
\big(
\mathbb{Z}_{2^{\alpha}}^*
\ , \times
\big)
\equiv
\big(
\mathbb{Z}_2
\oplus
\mathbb{Z}_{\color{Red}{2^{\alpha-2}}}
\ , +
\big)
.
$$
- The multiplicative group $\mathbb{Z}_{2^2}^*$;
is
a cyclic group of order $2$.
The multiplicative group $\mathbb{Z}_{2}^*$;
is
the trivial group.
If $n$ is coprime with $3pq$ then we can factor $n$ and hence we have:
$$
n^{3pq }\overset{3pq}{\equiv}n
\Longrightarrow
n^{3pq-1}\overset{3pq}{\equiv}1
.
$$
First case: All of $3, p, q$ are different.
By the above lemma,
we know that:
there is an integer $a$; with $\text{ord}_p(a)=p-1$.
On the otherhand $a^{3pq-1}\overset{p}{\equiv}1$;
which implies that $\color{Blue}{p-1 \mid 3pq-1}$.
Similarly one can prove that
$p-1 \mid 3pq-1$
and
$3-1 \mid 3pq-1$.
But notice that
$\color{Blue}{3pq-1=3(p-1)q}+\color{Purple}{3q-1}$;
similarly we have:
$3pq-1=3p(q-1)+3p-1$
and
$3pq-1=2pq+pq-1$.
So we can conclude that:
$$
\color{Blue}{p-1 \mid} \color{Purple}{3q-1}
\ \ \ \
\text{and}
\ \ \ \
q-1 \mid 3p-1
\ \ \ \
\text{and}
\ \ \ \
3-1 \mid pq-1
;
$$
the last divisibility condition implies that
both of $p,q $ must be odd;
you can check that $p=11 , q=17$
satisfies the above divisiblity conditions.
Why these are the least posible values?
$ \color{Green}{
\text
{As}
\
\color{Red}{\text{@Thomas Andrews}}
\
\text{has been mentioned:}
\\
\color{Red}{\text{"}}
\text
{we can assume}
\
p \overset{6}{\equiv} 5
\
.
\\
\text
{[
Because}
\
p−1∣3q−1
\
\text
{means}
\
p−1
\
\text
{is coprime to}
\
3
\
;
\text
{so}
\
p \overset{3}{\ncong} 1;
\
\text
{which implies}
\
p \overset{3}{\equiv} 2
\
\text
{.
]}
\\
\text
{Notice that}
\
p=5
\
\text
{doesn't work,}
\\
\text
{since}
\
3p−1=14
\
\text
{is not divisible
by}
\
q−1
\
\text
{for any}
\
q \overset{6}{\equiv} 5.
\
\\
\text
{So the smallest possible values for}
\
p,q
\
\text
{is}
\
11,17
\
.}
\color{Red}{\text{"}}$
Second case: All of $3, p, q$ are not distict.
We will show that this second case is impossible.
$p=3$ or $q=3$.
From assumtion of problem
we know that:
$3^{3pq} \overset{9}{\equiv} 3$;
so we have:
$0 \overset{9}{\equiv} 3^2 \overset{9}{\equiv} 3$;
which is an obvious contradiction.
$p=q$.
From assumtion of problem
we know that:
$p^{3pq} \overset{p^2}{\equiv} p$;
so we have:
$0 \overset{p^2}{\equiv} p^2 \overset{p^2}{\equiv} p$;
which is an obvious contradiction.
Consider a given positive integer $n \ge 1$, and a corresponding positive integer $K$, for which a prime $P$ exists such that $P$, $P + K$, $P + 2K$, $\ldots$, $P + nK$ are all primes. Note $K$ must be an integral multiple of the primorial $p_j\#$, where the index refers to the prime index (e.g., $p_1 = 2$, $p_2 = 3$, etc.) and $p_j$ is the largest prime $\le n$. Thus, the smallest possible $K$ would be $p_j\#$ itself. This is why the minimum $K$ for your example where $n = 5 = p_3$ is $30$ since $30 = p_3\# = 2(3)(5)$.
To prove $p_j\# \mid K$, first note if $P = p_i$ for some $1 \le i \le j$, then $p_i \mid P + p_i(K)$, so it can't be prime, which means $P \ge p_{j+1}$. Next, assume there's a $p_i$, with $i \le j$, where $p_i \nmid K$. Then $P$, $P + K$, $\ldots$, $P + (p_i - 1)K$ all have different remainders modulo $p_i$ (since if any $2$ were the same, say $P + qK$ and $P + rK$ with $r \gt q$, the difference of $(r - q)K$ must be divisible by $p_i$ but $0 \lt r - q \lt p_i$). Since there are $p_i$ possible remainders from $0$ to $p_i - 1$ among these $p_i$ values, one of them must be $0$. As it must be $\gt p_i$, it can't be prime. This shows the original assumption that $p_i \nmid K$ must be false.
A special case to consider is if $n + 1$ is prime, i.e., it's $p_{j+1}$. If so, then if $p_{j+1} \nmid K$, you must have $P = p_{j+1}$ since, otherwise, one of the $P + iK$ for $1 \le i \le n$ must be a multiple of $p_{j + 1}$ and $\gt p_{j+1}$, so it can't be prime.
Regarding proving there always exists a prime $P$ where, with $K = p_j\#$, you have $P + ik \; \forall \; 1 \le i \le n$ being prime, there's no general method I know of to prove this. Although I suspect such a $P$ always exists, the only thing known for sure now is that a $K$ and $P$ do exist for any positive $n$, as explained in the next paragraph.
As for finding the largest $n$ where there's a $K$, including a smallest such $K$, where $P$, $P + K$, $\ldots$, $P + nK$ are all prime, there is no such maximum $n$. Note the Green–Tao theorem states
... the sequence of prime numbers contains arbitrarily long arithmetic progressions.
Best Answer
Let $S(n)$ denote the sum, i.e. $$ S(n) = n + d(n) + d(d(n)) + \dotsb .$$ Note that $n$ cannot be larger than $2023$, and $d(n) \le n / 2$, as the largest divisor of $n$ is obtained by dividing $n$ by its smallest prime factor. This implies that $1012 < n < 2024$. This helps to reduce the search space a bit.[1]
Keeping on the theme of looking at the prime divisors of $n$, observe that if the prime factorization of $n$ is $ n = p_1 p_2 p_3 \dotsb p_m $, with the (possibly repeated) primes listed in decreasing order, then \begin{align} S(n) &= p_1 p_2 p_3 \dotsb p_m + p_1 p_2 p_3 \dotsb p_{m-1} + \dotsb + p_1 + 1 \\ &= p_1 \left( p_2 p_3 \dotsb p_m + p_2 p_3 \dotsb p_{m-1} + \dotsb + p_2 + 1\right) + 1 \\ &= p_1 S\left( \frac{n}{p_1} \right) + 1. \end{align} This implies that $$ S\left( \frac{n}{p_1} \right) = \frac{S(n)-1}{p_1}. $$ This greatly reduces the search space. With $S(n) = 2023$, the possible choices for $p_1$ are $2$, $3$, and $337$ (the factors of $S(n)-1 = 2022$). Then, since $p_1$ divides $S(n) - 1$, a brute force attack is possible (with a relatively small search space).
If $p_1 = 2$ (i.e. if the largest prime factor of $n$ is $2$), then it must be the case that $n$ is a power of $2$, i.e. $n = 2^k$ for some integer $k$. The only power of $2$ in the required range is $2^{10} = 1024$. But \begin{align} S(1024) &= 1024 + 512 + 256 + 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 \\ &= 2047 \\ &\ne 2023. \end{align}
If $p_3=3$, then $$ S\left( \frac{n}{3} \right) = \frac{S(n) - 1}{3} = 674. $$ But then $$ S\left( \frac{n}{3p_2} \right) = \frac{673}{p_2}, $$ where $p_2$ is the largest prime factor of $n/3$ (and thus the second largest prime factor of $n$). But $673$ is prime, so it is its only prime factor. Hence $S(n/2019) = 1$, which implies that $n/2019 = 1$. Then $$ S(n) = S(2019) = 2019 + 673 + 1 = 2693 \ne 2023.$$ Hence it is not possible that $p_1 = 3$.
The only possibility remaining is that $p_1 = 337$. Then $$ S\left( \frac{n}{337} \right) = \frac{2022}{337} = 6. $$ Repeating the argument made above, $$ S\left( \frac{n}{337p_2} \right) = \frac{5}{p_2}, $$ which implies that $p_2 = 5$, and that $S(n/1685) = 1$. Therefore the only possibility is that $n = 1685$. Observe that $$ S(n) = 1685 + 337 + 1 = 2023, $$ as claimed.
This exhausts the three cases. The only $n$ which gives the desired result is in the final case; this $n$ is $1685$.
[1] Having finished the problem now, it turns out that I didn't use any of this (well, not very much, anyway), but this search for "good" candidates by winnowing down on prime factors led me to the approach below, so I am going to leave this comment in the answer.
[*] John Omielan pointed out in the comments that a similar problem appears on AoPS. Their solution (with $S(n) = 2021$ instead of $2023$) is remarkably similar to my own, which is both somewhat gratifying (it helps me to believe that this is correct) and incredibly annoying (as it turns out that I just did a bunch of work that someone else has already done). But I got nerd-sniped by this problem, and put the work in, so I'll leave my answer. :/