This is a very tricky issue! Firstly, the verb in question is not actually lay, it's lie - "lay" just happens to be the past tense of "lie" in this case, just like was is the past tense of is. The definition of lie that applies here is
- to be placed or situated
That is, your problem was placed, or situated, or located within that part of the text. So the substitution is actually very good in this case, because "my problem was in that part of the text" is very similar to "my problem was located in that part of the text".
But can you use it in any case? No. Firstly, clearly "is placed in" is obviously not always a good substitute for "is". For example,
I am six feet tall
is obviously not the same as
I am located six feet tall (which doesn't make any sense)
and therefore you can't say
I lie six feet tall
Even when it refers to location, you can't always use it - for example,
I am in Rome
is a perfectly good sentence which means "My current location is 'Rome'", but
I lie in Rome
is very confusing, because it sounds more like "I lie down in Rome" or "I tell lies in Rome"; we just don't use lie as a general-purpose replacement for "is at this place". Using lie to mean placed or located is more of a poetic or metaphorical usage. Think of X lies in Y as something like "If you looked at Y, you would see the source or origin of X."
If this seems confusing, don't worry - lie and lay have many meanings, and are notoriously confusing even for native speakers.