$\def\cX{\mathcal X}\def\cY{\mathcal Y}$$\def\cX{\mathcal X}\def\cY{\mathcal Y}\def\Th{\mathrm{Th}}$The answer to the secondary question is an easy YES: for example, given an $L$-structure $\cX$ with domain $[n]$, let
$F(\cX)$ be the collection of pairs $(\cY,i)$ such that $\cY$ is an $L$-structure on $[n]$ isomorphic to $\cX$, $i\le n\log n$ is an integer, and the $i$th bit of the description of the lexicographically first isomorphism between $\cX$ and $\cY$ is $1$. Note that it is enough to have oracle access to one of $F(\cX)$ and $F(\cY)$; we do not need both.
The same kind of argument also works for the main question: given structurestructures $\cX$ and $\cY$ with domain $[n]$, and a partial self-map $f$ on $[n]$, let $\delta_\cX(\vec x)$ be the atomic diagram of $\mathcal X$ in variables $\{x_i:i\in[n]\}$, and $\delta_\cY(\vec y)$ be the atomic diagram of $\cY$ in variables $\{y_i:i\in[n]\}$. Then $f$ extends to an isomorphism $\cX\simeq\cY$ iff the existential second-order sentence (with no extra-logical symbols)
$$\exists F\,\exists\vec R\,\exists\vec x\,\Bigl(\delta_\cX(\vec x)\land\delta_\cY(F(\vec x))\land\bigwedge_{f(i)=j}F(x_i)=x_j\Bigr)$$
is true in some/every structure with $n$ elements, where $\vec R$ quantifies over all relations and functions of $L$ as used in $\delta_\cX$ and $\delta_\cY$, and $F(\vec x)$ denotes the sequence of values $F(x_0),F(x_1),\dots$. Again, using this oracle, we can construct an isomorphism $\cX\simeq\cY$ one element at a time; we only use the oracle for one of $\mathrm{Th}_2(\cX)$$\Th_2(\cX)$ or $\mathrm{Th}_2(\cY)$$\Th_2(\cY)$ rather than their join. (Actually, the join is pointness anyway: since $\cX\simeq\cY$, we have $\Th_2(\cX)=\Th_2(\cY)$, and $\Th_2(\cX)\oplus\Th_2(\cY)$ is trivially equivalent to $\Th_2(\cX)$.)
The only issue is whether this can be done in linear time. This is quite a tall order. Since thisit may depend on all kinds of details, let me assumestate for definiteness that we are using the standard multi-tape Turing machine model with a read-only input tape, write-only output tape, several work tapes, and an oracle query tape. The content of the oracle query tape is not erased or otherwise modified after making an oracle query. I’m assuming $\cX$ and $\cY$ are presented as input in the most obvious way as lists of tables of their relations and functions. Since $\Th_2(\cX)$ has to be presented as a set of strings over a finite alphabet, variables (both first- and second-order) in the formulas have to be identified using numerical indices; I will assue these are written in binary, so that if I use, say, $n$ variables, each takes $O(\log n)$ bits to write down.
We can write downNote that if we have only unary relations and constants, then the size of the input is $\exists F\,\exists\vec R\,\exists\vec x\,\bigl(\delta_\cX(\vec x)\land\delta_\cY(F(\vec x))\land\dots$ part$O(n)$, whereas the size of the formula onoutput is $\Omega(n\log n)$. Thus, the query tapetask is impossible to do in linear time with whatever oracle, as a linear-time machine does not even have the time to write down the result.
(Thus, the claim in the size ofquestion that “an isomorphism between them is clearly computable in linear time from $\mathcal X$ and$\Th_2(\cX\sqcup\cY)$”, given without any justification, is false in general. This claim is quite dubious for other reasons as well: since $\mathcal Y$$\cX\simeq\cY$, $\Th_2(\cX\sqcup\cY)=\Th_2(\cX\sqcup\cX)$, which is easily reducible to $\Th_2(\cX)$ itself. I thus cannot imagine having oracle access to $\Th_2(\cX\sqcup\cY)$ is in any way more helpful than just $\Th_2(\cX)$.)
I do not know how to implement the algorithm above in linear time, but as outlined below, it can be done with an extra $\log n$ factor (asor a little bit more in the purely unary case).
The diagrams $\delta_\cX$ and $\delta_\cY$ are basically just copies of the tables of the relations and functions) of $\cX$ and $\cY$, thus we can write down the $\exists F\,\exists\vec R\,\exists\vec x\,\bigl(\delta_\cX(\vec x)\land\delta_\cY(F(\vec x))\land\dots$ part of the formula on the query tape in time $O\bigl((|\cX|+|\cY|)\log n)$, where $|\cX|$ denotes the size of $\cX$ as an input string; the $\log n$ factor comes from variable indices of $x_i$ and $y_i$. (Actually, we also need to include the constraints that the $x_i$ are pairwise distinct, and likewise for $\vec y$. The obvious way, using a conjunction of $\binom n2$ inequalities, takes $O(n^2\log n)$ bits. We can do it more efficiently, but let’s not worry about that for now.)
Then we write down $\dots F(x_0)=x_0\bigr)$ and query the oracle; if the answer is negative, we modify it to $\dots F(x_0)=x_1\bigr)$, and so on, until we get a positive answer. Each such change istakes amortized constant time ifby the variable indices are written in unary; if they are written instandard analysis of a binary, it’s amortized constant time. Anyway counter; that is, it takes time $O(n)$ to find the image of $0$; we. We copy it to the output tape, and go on to add $\dots\land F(x_1)=x_0$ on the query tape, and continue. In this way, we construct the isomorphism in time $O(n^2)$ on top of the $O\bigl((|\cX|+|\cY|)\log n)$ initialization part which was linear in the size of the input.
Thus, if $L$ contains at least one at least binary relation or function symbol, the algorithm as a whole works in linear time $O\bigl((|\cX|+|\cY|)\log n)$, as the size of the input, $|\cX|+|\cY|$, is $\Omega(n^2)$.
What ifIf all symbols in $L$ are unary? Well, first of all, if we have only unary relations and constants, then the size of the input is $O(n)$, whereas the size of the output is $\Omega(n\log n)$. Thus, the task is impossible to do in linear time with whatever oracle, as a linear-time machine does not even have the timeneed to write down the resultwork harder. (So the claim in the first paragraph of the question is wrongAs mentioned above, by the way.) The best we can hope for in this case is to make it work in time $O(n\log n)$; that is, to have an algorithm that works in time linear in the combined size of the input and output.
I’m not sure whether that is possible to arrangearrange; the best I can do is $O(n\log n\log\log n)$.
We can reduce the number of oracle queries to $O(n\log n)$ if we use binary search to find the image of $i\in[n]$: i.e., instead of trying whether the image can be $0$, $1$, $2$, ..., we first determine the first bit of the image, then the second bit, and so on. To make sure that the individual queries do not take too much time to construct, we can introduce predicates for elements with a given bit set: the formula will now start with
$$\exists F\,\exists\vec R\,\exists\vec x\,\exists P_0,\dots,P_{\log n}\,\Bigl(\delta_\cX(\vec x)\land\delta_\cY(F(\vec x))\land\bigwedge_{\substack{i\in[n]\\j\le\log n}}(P_j(x_i))^{b(i,j)}\land\dots,$$
where $b(i,j)\in\{0,1\}$ is the $j$th bit of $i$, and $\phi^1=\phi$, $\phi^0=\neg\phi$. But just writing down(NB: This also implies distinctness of the $x_i$s.) The indices of all the new predicates in binarypredicate variables in thesethe $n\log n$ new conjuncts takestake $O(n\log n\log\log n)$ bits. The indices of the $x_i$ variables would take $O(n(\log n)^2)$ bits as written, but we can reduce this to $O(n\log n)$ by judicious quantification: instead of $\bigwedge_j(P_j(x_i))^{b(i,j)}$, write $\exists z\,\bigl(z=x_i\land\bigwedge_j(P_j(z))^{b(i,j)}\bigr)$. One can then arrange the whole computation to take time $O(n\log n\log\log n)$ (plus linear in the size of the input in case of nonunary symbols), but I’m not sure how to reduce it all the way down to $O(n\log n)$.