An old couple who are my friends, are so lonely that the walls are closing in/on them.
Is my phrase correct to say that they start to behave oddly?
You might want to use the phrase Stir Crazy. This generally refers to someone who's going a bit nutty due to prolonged loneliness or incarceration.
If you want to state that they're behaving in an odd fashion, you might change your sentence like this:
An old couple I know are so lonely they act like the walls are closing in/on them.
The portion I italicized could probably be replaced with a number of phrases.
I think the phrase "felt like the walls were closing in" usually describes a person who's feeling overwhelmed. Think about a criminal on the run. He knows the police are on his tail. He knows his friends are snitching on him. He senses that his problems are piling up, and it's just a matter of time before the police catch (or shoot) him.
Such a person may well feel like the walls are closing in on him. (Of course, loneliness can be overwhelming, too.)
There is another possible interpretation: A person is feeling claustrophobic. They're so tired of being cooped up indoors they're beginning to feel as if the walls are literally getting closer together.
In this context, your original sentence would suggest a couple that is 1) very lonely and 2) very bored or very tired of staying at home when other people are going out to parties and other fun events.
I do believe that the term "feeling the walls closing in" is anxiety. I has having an episode when I had a major presentation, a paper, a test, another paper, 4 classes (everything to this point was due the next day), an exam the next day, paper #3, and a dying grandmother. I'm in college BTW, but the feeling described above is apart of an anxiety attack.