Beginner level : Help in understanding from paper how the log-likelihood term has been obtained
Problem 1
The cost function is just the negative log posterior distribution of the unknowns $x$ conditioned on the data $y$ and hyperparameters. The optimization routine must minimize this cost function to obtain the MAP estimate.

Problem 2
As you correctly noted, the first four terms come from the $p(y|x)$ and $p(m)$ terms in the posterior. Next, note that there are priors on $x$ and $W$ as well defined to be Gaussian distributed (Eq. (13) and (20)). $x$ has a Gaussian distribution $N(0,I)$ and the $k^{th}$ column of $W$ follows $N(0, \nu_{wk}I)$. These lead to the last term in Eq. (39).

As for your final question, I could not find this method in the paper. Your definition of distance also seems wrong - perhaps you mean to say $(\mbox{dist}(\mathbf y_i, \mathbf y_j))^2 = ||\mathbf y_i - \mathbf y_j||^2 = (\mathbf y_i-\mathbf y_j)^T(\mathbf y_i-\mathbf y_j)$? Please clarify where you got the expression $p(d_{ij})$ from and how it is connected your original questions about MAP estimation.

Perhaps you are trying to impose a prior on the $\mathbf x$'s in such a way that if $\mathbf x_i$ and $\mathbf x_j$ are "close together," then $\mathbf y_i$ and $\mathbf y_j$ are also "close together." I would think that imposing a prior for this is not necessary because the first term in Eq. (39) is automatically taking care of this for you as explained below. 

Assume for the moment that $\mathbf m=0$ Then the first term in Eq. (39) will force $\mathbf y_i$ to be close to $\mathbf W^T\mathbf x_i$ by choice of $\mathbf x_i$. So if $\mathbf y_i$ and $\mathbf y_j$ are nearby, so will $\mathbf W^T \mathbf x_i$ and $\mathbf W^T \mathbf x_j$. In other words, $\mathbf x_i$ and $\mathbf x_j$ are close together in the Mahalanobis distance sense i.e. $(\mathbf x_i-\mathbf x_j)^T\mathbf W^T \mathbf W (\mathbf x_i-\mathbf x_j)$ should be small.

The MAP estimation problem can be written as
$$
\mathbf X _{MAP} = \arg \max _{\mathbf X} p( \mathbf X | \mathbf Y, \mathbf W). 
$$
Note that the posterior is parametrized by $\mathbf W$. We can simplify this using Bayes' rule:
$$
p(\mathbf X | \mathbf Y, \mathbf W) \propto p(\mathbf Y | \mathbf X, \mathbf W) p(\mathbf X) p(\mathbf W).
$$
Taking the negative logarithm, the MAP problem becomes a minimization problem:
$$
\mathbf X_{MAP} = \arg \min _\mathbf X [-\log p(\mathbf Y | \mathbf X, \mathbf W) -\log p(\mathbf X) -\log p(\mathbf W)]
$$
This can be further simplified by using the pdf of the various Gaussian densities and it will start looking a lot like Eq.(39). For example,
\begin{eqnarray*}
-\log p(\mathbf W) &amp;=&amp; -\log \prod_{k=1}^c p(\mathbf W_{:,k}) \\
&amp;=&amp; -\sum_{k=1}^c \log \frac{1}{(2\pi v_{wk})^{d/2}} e^{-\frac{1}{2v_{wk}} w_{ik}^2} \\
&amp;=&amp; \frac{1}{2}\sum_{k=1}^c \left[ d\log(2\pi v_{wk}) +\frac{1}{v_{wk}} \sum_{i=1}^d w_{ik}^2 \right].
\end{eqnarray*}

The rest of the terms can be derived with similar algebraic manipulations.