It's stated in a lecture note that if $\mathcal C$ is a small category and $\mathcal D$ is a category, then the class of functors from $\mathcal C$ to $\mathcal D$ is a set.
I asked a chatbot and it said that it's because "a small category has a set of objects and a set of morphisms, and the class of all functors from $\mathcal C$ to $\mathcal D$ is a collection of functions between these sets. Since the collection of all functions between two sets is itself a set, the class of all functors from $\mathcal C$ to $\mathcal D$ is also a set."
I get that the collection of all functions between two sets is itself a set, but I am not sure how $A := \text{Obj } \mathcal C \cup \displaystyle\bigcup_{X,Y \in \text{Obj } \mathcal C} \text{Mor }(X,Y)$. Certainly, since $\mathcal C$ is small, it suffices to show that $\displaystyle\bigcup_{X,Y \in \text{Obj } \mathcal C} \text{Mor}(X,Y)$ is a set. I know that $\text{Mor } (X,Y)$ is a set for each $(X,Y) \in \text{Obj } C \times \text{Obj } C$, the latter of which is a set. However, I am wondering why, in general, it's the case that $\displaystyle\bigcup{i \in I} \{X_i \}$ is a set when $I$ and any of $X_i$ are sets, i.e. why it's true that the union of set-many sets is a set. I read this wikipedia page describing the axiom of unions, as well as this post here, but I still don't get what the specific $\mathcal F$ (to use the notation from the wikipedia page) is to guarantee that the union of set-many sets is a set.
Also, after getting that the set of all functions from $A$ to $\mathcal D$ is a set, to apply the axiom schema of specification (Number 3 in the wikipedia link), we must have a finite $w_1,\dots,w_n,x,z,$ and $\varphi$ of one variable for the axiom schema of specification to work. I am wondering what exactly is the formula $\varphi$ (formulated precisely in the language of ZFC) that would enable us to say that the (sub)set of all functors from $\mathcal C$ to $\mathcal D$ is indeed a set? It seemed pretty difficult for me because I was not given that $\mathcal D$ is a small category.
I know this is a bit technical but I would be grateful for your clarification.
It seems there are several layers of confusion going on here.
The statement is false. Let $C$ be the category with a single object $*$ and a single arrow $\mathrm{id}_*$ (this is a small category). Let $D$ be a category with a proper class of objects. Then a functor $C\to D$ is determined by a choice of an object in $D$. More precisely, we have a class function mapping a functor $F\colon C\to D$ to its value $F(*)\in \mathrm{Ob}(D)$, which is surjective onto $\mathrm{Ob}(D)$, so if the class of all such functors was a set, then by the axiom of replacement, $\mathrm{Ob}(D)$ would be a set.
"I asked a chatbot..." Why? At present (December 2023), if you ask ChatGPT or the like about mathematics, it produces garbage more often than not. Worse, it produces very stylistically convincing garbage, so it can be difficult for a non-expert reader to tell that it's garbage. You should always be extremely skeptical of the outputs of large language models, and please don't try to use them to learn math. They will only confuse you further.
However, it is true that a union of a set-indexed family of sets is a set. That is, if $I$ is a set and $(A_i)_{i\in I}$ is a family of sets indexed by $I$, then $\bigcup_{i\in I}A_i$ is a set. Here's how to prove this in ZFC. First, the indexing of the family $(A_i)_{i\in I}$ is a function $f$ with domain $I$ such that $f(i) = A_i$. The range of any function whose domain is a set is a set, so we have a set $\mathcal{F} = \{A_i\mid i\in I\}$. Applying the axiom of union to $\mathcal{F}$, we obtain $\bigcup \mathcal{F} = \{x\mid \exists A\in \mathcal{F}\,(x\in A)\} = \bigcup_{i\in I}A_i$.
To address your last paragraph: it follows from the previous point that the collection of all arrows in a small category forms a set. Now it's easy to see that if $C$ and $D$ are both small, then the class of all functors $C\to D$ is a set. Indeed, we can form the set $\mathrm{Ob}(D)^{\mathrm{Ob}(C)}\times \mathrm{Mor}(D)^{\mathrm{Mor}(C)}$, the elements of which are pairs $(f,g)$ with $f\colon \mathrm{Ob}(C)\to \mathrm{Ob}(D)$ and $g\colon \mathrm{Mor}(C)\to \mathrm{Mor}(D)$. Now we can use specification to take the subset of those pairs which constitute functors. The formula will say: "for all $\varphi\in \mathrm{Mor}(C)$, $f(\mathrm{dom}(\varphi)) = \mathrm{dom}(g(\varphi))$ and $f(\mathrm{cod}(\varphi)) = \mathrm{cod}(g(\varphi))$, and for all $X\in \mathrm{Ob}(C)$, $g(\mathrm{id}_X) = \mathrm{id}_{f(X)}$, and for all $\varphi,\psi\in \mathrm{Mor}(C)$ such that $\mathrm{dom}(\psi) = \mathrm{cod}(\varphi)$, $g(\psi\circ \varphi) = g(\psi)\circ g(\varphi)$".