Can I use the following relationships to calculate the sides of the below triangle (in the picture)?
$tan5=\frac{AB}{6}$
$cos5=\frac{6}{AC}$
Can we use these formulas only for the right triangle? I heard that, but I'm not sure if I heard it right or not, if that's right, Why are these formulas used only for right triangles?

No you can't. The formulae
$$\tan(\theta) = \frac {\text{opposite}}{\text{adjacent}} \qquad \cos(\theta) = \frac {\text{adjacent}}{\text{hypotenuse}}$$
only apply when you have a right angle. In this case, angle $CBA$ is $120$ so these formulae don't apply.
The reason why it only applies to right angled triangles is simply because that is how the trigonometric functions are defined.