A sufficient condition is that $(B,\mathcal{Y})$ is a Polish (separable and completely metrizable) space with its Borel $\sigma$-algebra and $(A,\mathcal{X},P)$ is atomless.
This result is widely known, but it hard to find an exact reference for it. It follows from Proposition 9.1.2 and Theorem 13.1.1 in Dudley 2004, Real Analysis and Probability for the case that $A=[0,1]$, $\mathcal{X}$ the Borel sets and $P$ the uniform distribution (Lebesgue measure). Now on every atomless probability space, one can find a uniformly distributed random variable with values in $[0,1]$. I will sketch a proof of this below.
It is possible to generalize the result above slightly and allow for $(B,\mathcal{Y})$ to be a Souslin space with its Borel $\sigma$-algebra. To get this as a corollary to the previous result, use Theorem 9.1.5 in Bogachev 2006, Measure Theory.
Lemma: Let $(\Omega,\Sigma,\mu)$ be an atomless probability space. Then there is a random variable $f:\Omega\to [0,1]$ with $\mu\circ f^{-1}$ being the uniform distribution.
Proof: Using that finite atomless measures have convex range, we can construct a sequence of independen random variables $(g_n)$ with $g_n:\Omega\to\{0,1\}$ that put equal probability on both numbers. This induces a random variable $g:\Omega\to\{0,1\}^\mathbb{N}$ with fair coin-flipping measure as its distribution. The function $\{0,1\}^\mathbb{N}\ni(x_n)\mapsto\sum_n x_n/2^n$ is measurable and composing it with $g$ provides us with $f$.