I'm afraid this is one of those sad but true situations. Too many students are blocked by their own expectations. Too often those expectations are based on early experience and then reinforced continuously. Every time they seem to fail, the poor sense of self worth is deepened. You want to try to break that cycle.
There are two solutions (at least). One for the whole class and one for the individual.
For the class you need to always teach with the attitude that yes you can. That this may not be easy, but it is do-able, even if it takes work. You shouldn't say things like "this may be too hard for some of you" or anything implying that. You can say "I struggled with this when I was younger, but pushed through the block." Good teaching practice in general can help with this. Peer instruction, pairing, group work, peer feedback can all help. Providing a way for them to get questions answered as they arise will help so they don't need to wait for an answer. Encouraging questions helps - even requiring questions - with points given for "participation" helps. Value questions over answers, actually (unlike this site). If you keep an index card for each student (assuming reasonable numbers) you can annotate it as questions and discussions occur. Keep these cards with you as you teach, of course. Cards on your office desk are less valuable.
For the individual, you may need to spend some time exploring what got them to the situation they are in and why. When was the first time they noticed this "inability"? What happened then that gave them that idea? Many people get into this situation and then miss a lot of essentials that leave them behind their classmates making it harder and harder to catch up or change their self-perceptions. You need to try to break that cycle. Sometimes tutoring is available, but you may need to instruct the tutor to have it properly effective.
The key idea, however, is to assure, somehow, that the student has success and recognizes it, even if it is a small success. Sometimes pointing out to them that they were abandoned by earlier teachers gives them some incentive to succeed.
One way to assure success is to depend less on "all or nothing" examinations and base grading more on cumulative work submitted. Permitting repeated work and re-grading is a powerful technique, but can, if not monitored, lead to the student getting farther behind, as the re-work takes time and focus. If a course is "worth" 1000 points, then each of 8 projects is worth 100, with resubmission after grading permitted. The remaining points can be distributed otherwise. Some people even permit re-taking examinations.
It is likely that the reinforcement of failure comes from many directions. You can/should discuss the situation with your colleagues and develop an overall plan for any such student. Hopefully your rules and regulations don't make that impossible. Parents can also help in some situations, perhaps by providing tutors or counseling. In particular, you may need to educate your peer educators that it isn't proper behavior to teach only the obviously teachable, especially if that is only the best students who may, in some ways, be the easiest to teach.
You should also ask this same question at Math Educators. Math teachers have long faced this situation at all levels. Sometimes in an Algebra class, for example, you learn that students don't actually know how to add two numbers. In math or CS you may need to take the student back a long way to fill in the gaps they have.
One person close to me thought he was dumb in math. In fact, he was bored in school and being bored caused a bit of trouble. This resulted in at least one teacher ignoring his instruction. He could only add by counting on his fingers. Later on, he took a Calculus course and did very well, surprising himself. I knew that he had unrealized ability, but it was hard to get that idea through to him.