You are right about the statement for regular languages. This is a well known fact usually expressed by the phrase that regular languages are closed under square root (quite unfortunately, the operation you are describing is sometimes even denoted by $\sqrt{A}$) – the details of the proof should be easily googlable.
The case of context-free languages is more interesting. Let us take the following language:
$$A = \{a^i b^i c^j a^n b^m c^m ~|~ i,j,n,m \in \mathbb{N};~i,j,n,m \geq 1\}.$$
The language $A$ is obviously context-free.
Now, the language $\{x ~|~ xx \in A\}$ contains precisely all words $x \in {\{a,b,c\}}^*$, such that $xx = a^i b^i c^j a^n b^m c^m$ for some suitable $i,j,n,m$. Quite obviously, this is the case if and only if
$$x = a^i b^i c^j = a^n b^m c^m$$ for some $i,j,n,m$. But this directly implies $i = j = n = m$. As a result, the square root of $A$ contains precisely all words $x \in {\{a,b,c\}}^*$, such that $x = a^n b^n c^n$ for some $n$. Put in another way,
$$\{x ~|~ xx \in A\} = \{a^n b^n c^n ~|~ n \in \mathbb{N};~n \geq 1\}.$$
This language is not context-free. So the family of context-free languages is not closed under square root.