Like all passages, context - historical or cultural setting - is key to accurately understand their meaning.
The Corinthians were having a unique issue with being distracted and living lives somewhat out of control more than many other churches Paul ministered to. In part because Corinth was a hub of commerce ripe with both material and sensual distractions. As a result Paul felt it necessary to help them understand that even though they are under grace there are consequences to living contrary to God's righteous standard - i.e. the law.
What is interesting about these verses is what each says that is the same as well as different. This is very instructive in determining what is meant by what they have in common.
The first talks about not being dominated (ruled/controlled) by something and the latter about how some things do not “build up” or strengthen us.
One talks about how some things we experience externally have a bad affect on us - dominate us - the other about how they hinder something good internally - being built up.
How does the first part of these verses relate to the last part of each?
Even though we are free in Christ and can never do anything to cause his love to be separated from us, living contrary to God's direction/law still has negative consequences. We may go to heaven if we die from jumping off a building, but we still die. Being free to do anything we want does not necessarily mean doing it is good for us. This can cause us to be dominated by those things that are otherwise Lawful or hinder us from being built up our relationship with God - i.e. they can't and won't be legally held against us because Christ already fully satisfied the requirements of the law for us. But just because it is lawful does not mean it is good or helpful.
Our lawful status as God's beloved children is fully established in Christ. Nothing we do or don't do will affect this. We are perfectly received and children of God no matter what we do or experience or don't experience.
Paul's point is in Christ nothing we do or don't do will be held against us legally i.e. “All things are lawful,”
However living any way we wish is not in our best interests no more than a child in a candy or toy store doing as he wishes is in his. As our loving father he gives us direction to avoid what is harmful; things that could dominate us and hinder our pursuit of Christ.
Paul is simply addressing the debate of the interplay of grace and law. Being under grace does not mean the law no longer has value or should be ignored. What has changed is how we approach or relate to the law not the law itself.
The very reason we are under grace is so that we might naturally - actually supernaturally - and organically fulfill the law in all our words and actions.
When we understand the law is merely an expression of God's loving will and direction for us this makes even more sense. The ultimate end of all God's directions is that we might love him with all our heart soul mind and strength and our neighbor as ourselves. This is a good thing not bad. It is not just honoring to God but good for us and our neighbor.
The question isn't whether we are allowed - is it lawful - to do certain things or not but does our conduct hinder or strengthen our walk and relationship with God and better enable us to honor him. All things being lawful does not mean all things are good for us.