There are three independent questions in your question and so let’s attempt to answer each one of them one at a time.
Your first question – "Are there reasons why companies prefer this type of structure?" - has two Reasons depending on the kind of organization you are dealing with.
Reason 1 – Organizations / Managers who believe in the idea of focus and very little multi-tasking.
These breed of organizations / managers / leadership believe that every time you perform a task switch you lose out on time and efficiency.
These folks would strictly advice against multi-tasking. Joel Spolsky and Scott Berkun are from this school of thought and so am I .
A few organizations take this forward and prefer specialized teams where each person is doing just one function and doing it really well without any deviations or indulging in cross functional tasks or even multiple tasks of the same kind.
In case of these companies the underlying intention is to keep the focus of the team on one thing and cultivating serious specializations.
Reason 2 – Organizations and Management which is built of the foundations of insecurity.
This breed of organizations / managers / leadership believe that employees are replaceable cogs in a larger organizational machinery.
Each part of a machine performs one and only one function and is replaceable with another part that performs that function. Cross function teams who see their work as art with a passion to excel in more areas than one will make this breed of organizations / managers very nervous.
If you ask me, 8 / 10 companies who prefer rigidly separated departments compared to cross functions do so because they have a culture and management built around the idea of insecurity.
Of course there are some who genuinely want to encourage focused expertise but those organizations are hard to come by.
Now on to your second question - Does it offer more opportunities to learn from team members working in the same field?
Yes it does if the intent is to build teams around focused talent and very little cross functional task switching.
But if these rigidly separated departments are built with the intentions of turning employees into cogs, learning opportunities are going to be very few and people are mostly going to act as automatons doing their tasks in a for-loop.
Moving on to third question:
"I've especially seen this in agencies where people are involved in many projects simultaneously. Are there environments where cross-functional teams are a bad idea?"
Well if people are involved in multiple projects simultaneously, there is very little attempt to avoid multi-tasking. In most of these cases I would think that Reason 2 I talked about applies.
Unless you are someone writing a specialized module that controls an aircraft or a defence submarine and that’s all you've done for the most part of your life, I would invariably prefer cross functional teams compared to rigid department.
Multi-tasking can still be avoided by ensuring that folks only have one thing on their plate at a time but they can work on multiple areas or functions one at a time helping both them and the team grow.
Learning in a cross function team tops learning in a specialized team in most day-to-day cases.