When you solve a problem like this, you are using a system of reference (actually you use one in all problems, but here it is very explicit). In this case, the easiest one is y in the vertical and x in the horizontal.
Almost all the forces are already in one of these 2 directions. Namely, you have all the weights pointing downwards, so in the -y direction and all normal forces pointing upwards, so +y direction. But you have a force (the one applied to body A) that is in neither directions purely. It is in a crooked direction, so it has a component in the y-axis and another in the x-axis.
That is why you use sine and cosine. You are calculating how much of this force is in the vertical direction (projection in the y-axis) and how much is in the horizontal direction (projection in the x-axis).
Be very careful when asking sin or cos, because they depend on the angle you choose to represent the vector. In this case, the exercise says it is an angle with the horizontal, so a cosine will give you the horizontal component (adjacent to the angle), while sine will give you the y-component (opposite to the angle).
But as it was said before, the best you can do is to draw a diagram and realize which component the sine or cosine of that angle will give you.
As it was also mentioned, limiting cases help a lot!! For instance, in your particular case, you could ask:
"If the angle were 0 with the horizontal, what do I expect?"
Well, if it was 0, that means it is completely in the horizontal direction, therefore you expect a cosine there, since cosine(0) = 1, so all your vector is in the horizontal component. While for the y-component you get sin(0) = 0, which is also expected since you have no projection there at all.
the case of 90 degrees is also very good, since you can follow the same reasoning and realize that the roles change. You expect all of the force in the y-axis and nothing on x. And you get that from sin(90) = 1 and cos(0) = 0.
But again, do not memorize, this will always be sine and this always cosine, since it is very easy to get tricked by doing this. One can give you the angle with respect to the vertical axis and sine and cosine change places.