Generally, any author of a creative work (book, painting, computer program or whatever) is granted certain monopoly rights on the production and use of that work. The specific rights, and the length of time those rights apply, are encoded into national laws.
As a general rule, you cannot make a copy of that specific work. There are, however, many exceptions.
1) You may copy ideas, patterns, and designs. You may not copy specific expressions of those ideas. So, you could write a song about what a great state Oklahoma is, even if you are inspired by Rogers and Hammerstein's "Oklahoma!", but you couldn't include lines like "There's a bright golden haze on the meadow", since Rogers and Hammerstein wrote that specific expression.
2) You may copy expressions, if you have permission. There are a million ways to get permission to do that, many involving exchange of funds. The general rule is: if you have permission from the copyright holder, you may do what he permits.
3) You may perform acts that would otherwise violate copyright for certain "fair uses." What constitutes fair use is a very complex subject. Your use probably isn't fair use.
4) Any work created by a US Govt employee as part of his job description is not subject to copyright. Works created by US Govt contractors are.
5) Any work sufficiently old (for a very complex function of old()) is not subject to copyright. You may write "Romeo and Juliet", but you probably ought not write "Lord of the Rings."
6) In some countries, any work for which the author has explicitly disclaimed copyright is not subject to copyright. This is sometimes done with a statement like "I hereby place this code in the public domain."
So, what does all of this have to do with your question? Simple:
1) The work that you looked at is subject to copyright. You may not, generally, make a copy of it.
2) The authors of the work have given you prior permission (subject to a certain contract) to use and copy the work in certain ways. That is the definition of "open source." To understand what permissions you have, you must look at the "copyright notice" or "license notice" near the top of the source-code file, or otherwise packaged in the source code.
3) If you didn't copy any of their code, then you don't need their permission. Copyright applies to specific expressions of ideas, not the ideas themselves. If I write an implementation of quicksort(), then my source code is subject to copyright, but the algorithm that I use is not.
I am not a lawyer. These are general statements, and may not specifically apply to your situation.