How do I get entries of a child category, related to a parent category, defined in a URL segment?
I don't think that there's a "relation" between categories and their sub-categories.
But that's what you currently have as a parameter on craft.categories.
Use the ancestorOf() parameter instead to filter your subcategories:

{% set mainCategory = craft.categories.group('section').level(1).slug(secondSeg).first() %}
{% set secondLevelCategories = craft.categories.ancestorOf(mainCategory).slug(lastSeg) %}