Is it normal in computer science courses that one can't use open source code to solve exercises on courses even if the licenses of the code allows to use the code? I was confused as I used some code, gave source where I found the original code but still the lecturer said we have to learn to do the code on my own.
This is a quite generic question, so there is no real answer to it. You need to look at it from the course perspective as well as from the Open Source license perspective.
There are different Open Source licences available, but most of these should allow you to use them for creating derivative work. This might mean Open Sourcing your solution also though (in case of a copyleft license such as GPL).
I however suspect that your course wanted to teach you more basic concepts, therefore expecting you to come up with a solution by yourself. There is no clear answer to your question, however, more complex exercises would nearly always rely on the usage of Open Source software, such as SDKs, programming languages, libraries and frameworks.
I would assume that the lecturer wants you to write the code yourself; copying and pasting from an existing piece of code (no matter the licence and how you reference it) does not demonstrate that you have learnt the skills the lecturer is trying to teach you. That being said, using existing code to point you in the right direction would probably not be a problem.
As indicated by other answers, generally the purpose of a computer science programming assignment is to demonstrate learning of various core concepts. If one just uses libraries of code, then there is the possibility that coders might never learn to code those components on heir own.
However, for many programming situations, using appropriate open source libraries, and even snippets from Stack Overflow would be quite acceptable and efficient. What computer students (and even some professionals) forget to do is to acknowledge the sources used. To submit someone else's code without appropriate annotation and citation would make it appear as it was your own. Submitting someone else's work as your own would, in most university situations, be an "unfair means" offence and, if detected, trigger some form of disciplinary procedure. You should always properly acknowledge and cite the source of someone else's code. This should be in code comments and also indicated in any corresponding documentation.
I have to explain this to students in the coding laboratories so often!