This particular teaching of Jesus is one of the most difficult for people to accept, because it goes against our strongest evolutionary instincts.
But to examine these two paragraphs in their context, we need to also include verses 25-27 and 34-35:
25 Large crowds were traveling with Jesus, and turning to them he said: 26 “If anyone comes to me and does not hate father and mother, wife and children, brothers and sisters—yes, even their own life—such a person cannot be my disciple. 27 And whoever does not carry their cross and follow me cannot be my disciple.
28 “Suppose one of you wants to build a tower. Won’t you first sit down and estimate the cost to see if you have enough money to complete it? 29 For if you lay the foundation and are not able to finish it, everyone who sees it will ridicule you, 30 saying, ‘This person began to build and wasn’t able to finish.’
31 “Or suppose a king is about to go to war against another king. Won’t he first sit down and consider whether he is able with ten thousand men to oppose the one coming against him with twenty thousand? 32 If he is not able, he will send a delegation while the other is still a long way off and will ask for terms of peace. 33 In the same way, those of you who do not give up everything you have cannot be my disciples.
34 “Salt is good, but if it loses its saltiness, how can it be made salty again? 35 It is fit neither for the soil nor for the manure pile; it is thrown out.
"Whoever has ears to hear, let them hear.”
The meaning of the translation 'hate' here has been examined in other questions on this site. The words 'love' and 'hate', as translated throughout the Bible, particularly before Jesus' death, are less concerned with understanding and compassion as they are about value and preference. So when Jesus says to 'hate' something or someone, he means to 'prefer less' - effectively to downvote. And when he says to 'carry their cross and follow me', he literally means to be willing to face their own physical, possibly even painful, death.
What Jesus is asking of his disciples is to stop favouring their connection to family, to stop making choices in life based on the benefit and survival of themselves and their own kind as a priority, and to instead open their minds and hearts to the potential of a much more universal and eternal connection to life. It's a big ask.
He then gives examples to illustrate 'the same way' they should consider their commitment to this task. You wouldn't start building a tower if you hadn't considered the cost of following it through to completion. You wouldn't go into war against a larger army, a seemingly insurmountable task, if you hadn't seriously thought about what it would take to defeat them. And if it didn't seem likely, you would seek an alternative solution rather than forge ahead in a battle you know you will lose.
So he wants them to think carefully about what is being asked of them in becoming a disciple. Because it isn't going to be easy, and it isn't achievable while they still strive for the strength, benefit and survival of their biological or genetic connections to others or their own physical connection to life above everything else. That is still a good life, but it is not following Jesus. All of these physical and biological connections must mean nothing to them if they are to truly follow Jesus.
What many consider to be the purpose of life in general prevents them from achieving the task Jesus has set for his disciples. If we believe we are salt, wouldn't we feel worthless if we lost our saltiness? So, too, if we believe we are here to ensure the survival, continuation and benefit of our genetic code, then we won't make choices that would cause us to lose that, would we? Jesus asks people to think about what they are trying to achieve here in following him, and to listen carefully to what the task is, because not all of them will have the right perspective in life to be a disciple. This isn't about risking everything you value in this life - it's actually about a paradigm shift: about different values altogether.
Understanding this teaching is fundamental to realising that all life is interconnected, past present and future, in such a way that the strongest connection we are aware of towards another human being is equal to our connection to each and every element of life in the universe - ever. It is only our awareness of that connection that differs. This is the paradigm shift, and it's a tough one to grasp.