How are torques determined in equations of motion for multibody systems? In classical mechanics of multibody systems, one often ends up with equations for $n$ torques for $n$ links:
$$\tau_i= A_{ij}\ddot{\theta}_j + B_{ijk} \dot{\theta}_j \dot{\theta}_k + C_i  ,$$
with certain quantities $A$, $B$, and $C$ which can be defined elsewhere.  The aim is then usually to solve these equations numerically for $\dot{\theta}$ and $\theta$.
However, how can this be done without knowing what the torques are, because $\tau$ depends on the angles and angular speeds.
 A: You need a simulation loop which integrates $\ddot{\theta}$ to get $\dot{\theta}$ and $\theta$ at a later time.
So at each time steps follow these steps

*

*Known vectors of joint speeds and angles $\dot{\boldsymbol{\theta}}_n$ and $\boldsymbol{\theta}_n$ at time $t_n$, or initial conditions for the first step. Calculate coefficient matrix $\bf A$, and vectors $\boldsymbol{B}$ and $\boldsymbol{C}$.

*Calculate torques $$\boldsymbol{\tau}_n = \tau(t_n, \boldsymbol{\theta}_n, \dot{\boldsymbol{\theta}}_n)$$

*Solve system for the vector of accelerations $$\ddot{\boldsymbol{\theta}}_n = \mathbf{A}^{-1}\left( \boldsymbol{\tau}_n - \boldsymbol{B}( \dot{\boldsymbol{\theta}}_n) - \boldsymbol{C} \right)$$

*Use an integration scheme to find the joint angles and speeds at the next step $$\dot{\boldsymbol{\theta}}_{n+1} = \dot{\boldsymbol{\theta}}_n + h\, \ddot{\boldsymbol{\theta}}_n$$ $${\boldsymbol{\theta}}_{n+1} = {\boldsymbol{\theta}}_n + h\, \dot{\boldsymbol{\theta}}_n$$ $$ t_{n+1} = t_n + h$$

*Repeat from step 1. until the target time is reached.

Of course, the integration scheme above is for illustration purposes, as typically a multistep process is used coupling together steps 1 to 4 .
To clarify, in step 2., which is the question here, you can formulate the joint torques from the free body diagrams of each body.
Joint i is has rotation axis direction $\boldsymbol{z}_i$ and moment vector at the joint $\boldsymbol{M}_i$ then the joint torque is
$$ \tau_i = \boldsymbol{z}_{i}\cdot\boldsymbol{M}_{i} $$
For example a simple pendulum with the pivot at the origin has moment vector due to gravity as
$$ \boldsymbol{M}_i = \pmatrix{\ell \sin \theta \\ -\ell \cos \theta \\ 0} \times \pmatrix{0 \\ - m g \\ 0} = \pmatrix{0 \\ 0 \\ -m g \ell \sin \theta} $$
the joint axis is $\boldsymbol{z}_i = \pmatrix{0 & 0 & 1}^\top$ and so the joint torque is the dot product of the two
$$ \tau_i = \boldsymbol{z}_i \cdot \boldsymbol{M}_i = -m g \ell \sin \theta $$
