I will try to answer your questions with a "line-by-line" comment.
First, some background definitions.
a) see Enderton, pag.212 :
We say that a formula $\alpha$ of formal number theory $T$ functionally represents a function (say, for simplicity, with two argument places) $f : \mathbb N$ x $\mathbb N \rightarrow \mathbb N$ when, for every $a, b \in \mathbb N$ , if $c=f(a,b)$, then
$T \vdash \forall v_3[ \alpha (S^a(0), S^b(0), v_3) \leftrightarrow v_3 = S^c(0)]$.
b) see Enderton's definition (pag.235) :
Let $\theta (v_1,v_2,v_3)$ functionally represents a function whose value at <# $\alpha, n$> is #($\alpha (S^n0)$).
Now, your questions :
Suppose the numeral for the godel number for the formula theta( v1,v1,v3)is q.
I will rephrase it as :
Suppose that the g-number of the formula $\theta (v_1,v_1,v_3)$ is $q$ [i.e. $q$ = # $\theta (…)$ ; the corresponding numeral will be : $S^q(0)$ ].
Then theta(q,q,v3) is that " v3 is the numeral for the godel number of theta(q,q,v3)".
Then the correct interpretation of $\theta (S^q(0), S^q(0), S^n(0))$ will NOT be " $n$ is the godel number of $\theta (S^q(0), S^q(0), v_3)$ ", because $\theta$ functionally represents a function whose value at … where $\alpha$ must have only one free variable, and $\theta (v_1,v_1,v_3)$ has two free variables.
So, you must start with $\forall v_3 [\theta (v_1,v_1,v_3) \rightarrow \beta (v_3)]$; now you have a formula of “type” $\alpha (x)$ (with only one free variable $x$).
Let $q$ be its g-number (i.e. $q$ = # ($\forall v_3 [\theta (v_1,v_1,v_3) \rightarrow \beta(v_3)] )$ ); then, substituting $S^q(0)$ into its (free) argument place you will obtain the new formula $\forall v_3[\theta (S^q(0), S^q(0), v_3) \rightarrow \beta (v_3)]$; call it $\sigma$ with a new g-number : $s$ = #$\sigma$.
Because $\theta$ functionally represents a function whose value at is #$\sigma$, we have that : $\forall v_3 [\theta(S^q(0), S^q(0),v_3) \leftrightarrow v_3 = S^s(0)]$.
Taking v3 as a free variable , substituting it by a numeral should give a closed sentence.
So if we substitute S0 for v3, do we get
Theta(q,q,S0) is " S0 is the numeral for the godel number of theta(q,q,S0)"?
Or is it
Theta(q,q,S0) is "S0 is the numeral for the godel number of theta(q,q,v3)"?
In general, $\theta (S^q(0), S^q(0), S^n(0))$ will be interpreted as " $n$ is the g-number of the result of the substitution into the formula with g-number $q$ [i.e.$\forall v_3 \theta(v_1,v_1,v_3)$ ] with the numeral $S^q(0)$, i.e. $n$ = # $\forall v_3 [\theta... ](v_1/S^q(0))$.