Relationship between the TQFTs in Kapustin-Witten and Ben-Zvi-Sakellaridis-Venkatesh In upcoming work of Ben-Zvi-Sakellaridis-Venkatesh, (see for instance these notes or this lecture) some important aspects of the Langlands correspondence are stated in the language of topological quantum field theory. We have a TQFT i.e. a functor $A_G$, and it takes for example, a curve $C$ over $\mathbb{F}_{q}$ and returns the vector space $A_G(C)$ of unramified automorphic forms which live on $\mathrm{Bun}_G(C)$. It can further take a local field $F_x$ (localization of the function field of $C$ at some point $x$ of $C$) and return the category $A_G(F)$ of smooth representations of $G(F_x)$, and we can put them together and apply $A_G$ to $C\setminus S$, $S$ a finite set of places, to get $A_G(C\setminus S)$, the vector space of automorphic forms with prescribed ramification at $S$. In this picture, we are taking $C$ and the formal puncture disc around $x$ to be the analogues of $2$-manifolds and circles in 2D TQFT.
It has been mentioned that this is in some way related to (or perhaps inspired by) the work of Kapustin and Witten on gauge theory and geometric Langlands (over $\mathbb{C}$). In this work Kapustin and Witten construct a topological field theory on a manifold of the form $M=\Sigma\times C$ where $C$ is the Riemann surface of geometric Langlands, and, upon taking $C$ to be small compared to $\Sigma$, they show that the effective field theory on $\Sigma$ can be described by a sigma model of maps from $\Sigma$ to $\mathcal{M}_{H}(G)$, the moduli of semistable Higgs bundles on $C$. Then by some construction involving the "canonical coisotropic brane" in section 11 of that paper they make contact with the Langlands program by describing how to build a sheaf of D-modules on $\mathrm{Bun}_G$. Then S-duality on the gauge theory makes ${}^{L}G$ appear and the hyperkahler nature of $\mathcal{M}_{H}({}^{L}G)$/nonabelian Hodge correspondence connects this with the moduli of vector bundles with flat connection and the geometric Langlands correspondence appears as homological mirror symmetry between $\mathcal{M}_{H}(G)$ and $\mathcal{M}_{H}({}^{L}G)$.
The work of Kapustin-Witten, in their paper is a "topological field theory" in that it is independent of the metric. The language of TQFT as a functor, as far as I know, does not show up in the paper (although it does get a little mention in this later survey by Kapustin).
In the talks of Ben-Zvi linked to above, the TQFT that they are considering is supposed to actually go up to 4-dimensions, and though the examples I mentioned in the first paragraph are just the 2- and 1-dimensional part. From what I infer this being 4-dimensional is supposed to be somewhat connected to Kapustin-Witten.
How does one reconcile the two? What is the 4-dimensional part of the TQFT of Ben-Zvi-Sakellaridis-Venkatesh? How is this related to the manifold $M=\Sigma\times C$ of Kapustin-Witten?  In the MSRI notes linked above, there is a table on page 9 which says the 4-dimensional part should be periods. How is this so? In the same work periods are also supposed to be related to boundary conditions, which pick out a specific object of the output of the TQFT. However in the survey of Kapustin (in section 0.5) boundary conditions are the output of the 0-dimensional part of a 2-dimensional TQFT. What should the 3-dimensional part be?
 A: The (fairly poetic and ill-formed) idea in this story is that the Kapustin-Witten story and the Langlands program are about the SAME four-dimensional TQFTs, but evaluated on different "manifolds" - i.e., to get even more polemic, there isn't a separate "geometric Langlands" and "Langlands" but one general story evaluated in different settings. [There are more details available in the lecture notes from a class I taught last year linked to in this question LMS Lectures on Geometric Langlands]
As Will Sawin explained, the spaces of automorphic forms and categories of smooth representations are the values not on 2- and 1-manifolds but on (would-be) 3- and 2-manifolds, while the geometric Langlands correspondence is primarily about the value on 2-manifolds -- the $C$ you speak of. One way to phrase this: KW study the reduction of the 4d TFT on $C$, which is a 2d TFT (the value on $\Sigma$ is the value of the original 4d theory on $C\times \Sigma$). Now we're in the more familiar realm of eg mirror symmetry. A 2d TFT has a category of boundary conditions (the "category of D-branes" or value on a point in the functorial language), which is what the 4d TFT assigns to $C$. KW interpret these categories (on the two sides of the correspondence) as the automorphic and spectral categories (A- and B-sides) of the geometric Langlands correspondence.
This matches local Langlands, which in this interpretation is also an equivalence of categories attached to 2-manifolds -- this agrees with the Fargues-Scholze interpretation of local Langlands as geometric Langlands on the Fargues-Fontaine curve. (One subtle note: the category attached to a local field on the automorphic side is not actually just the category of smooth reps of G, but a much bigger category containing smooth reps of all pure inner forms of G and a family of smaller groups attached to so-called G-isocrystals -- this is essential to match the spectral side, where coherent sheaves on stacks of Langlands parameters are very large categories even for $\mathbb G_m$..)
In the work with Sakellaridis and Venkatesh we study the arithmetic counterpart of the work of Gaiotto and Witten on boundary conditions in the 4d theory and the effect of Langlands duality on them. As you say the point is that period functionals on automorphic forms appear in this dictionary -- they're the values of the theory on a "4-manifold" of the form [global field] x interval, where one end of the interval is marked by a spherical variety for $G$. As Will Sawin explained, the trace formula also appears naturally as the value on a 4-manifold (product with a circle).
A: A curve $C$ over $\mathbb F_q$ has dimension $3$ in this perspective (which is why you get a vector space) and a local field has dimension $2$ (which is why you get a category. So one only has to go up one dimension higher to get the four-dimensional theory.
Associated to the "product $C \times S^1$", we would take the dimension of the space of automorphic forms.  This is not well-defined as it is infinite-dimensional, but if we consider the space of automorphic forms with prescribed ramification at some finitely many points, we can get a finite number, and this corresponds to a four-manifolds with boundary conditions imposed on some surfaces (the "products" of closed points of $C$, which have dimension $1$, with $S^1$).
The trace of a Hecke operator on the space of automorphic forms is also part of the four-dimensional theory, where we have now inserted a line operator supported on a "1-dimensional submanifold" in our "4-manifold" (a closed point times a point of $S^1$).
Possibly any number that appears in the theory of automorphic forms can be expressed as arising from a four-manifold with suitable boundary conditions imposed.
The relation to Kapustin-Witten here is that a curve over a finite field behaves something like a product of a Riemann surface with a circle, so when we take the product with another circle, we get the product of a Riemann surface with a torus, which fits into the $\Sigma \times C$ picture.
