This question is similar to the following, which have answers:
"For" a period of time is almost always correct, but you can sometimes omit it when speaking.
To solve this yourself, start by simplifying the sentence.
You are correct when you say that the main difference is the use of "for" in the examples. But the examples are just different enough, with the use of "of" and other phrases, that you may be tempted to think that something about them is different that causes "for" to be correct in one, but not the other. (But which one?)
Let's see if this is so. The way you can solve this yourself is to recognize inversion and simplify. Perhaps you already did this!
Starting with your quote, recognize these are questions, so they need question marks:
For how many weeks is the lecture series given?
How many weeks of the lecture series can non-engineering students attend?
The first one of these sounds natural. The second one sounds awkward, but it would be understood by any native speaker. Let's see why this is:
Undo the inversion, and turn it into a sentence, not question.
The lecture series is given for how many weeks.
[Non-engineering] students can attend how many weeks [of the lecture series].
Simplify by taking out words, like prepositional phrases, that don't affect the meaning.
The series is given for how many weeks.
Students can attend how many weeks.
(We don't usually use 'how many' in a sentence, so you change change it to be the following to understand the structure).
(1) The series is given for [a few] weeks.
(1) The series is given for [three] weeks.
(2) Students can attend [a few] weeks.
(2) Students can attend [three] weeks.
The only difference between the first example (The series is given) and the second (Students can attend) is the use of passive voice, which has no impact on what comes after the verb (the length of time).
So now we see, even though the two sentences (questions) in your example sound quite different, they really only have one important difference, whether the "for" is there.
There is nothing else in your example sentences that's grammatically different, so they should be written the same way.
So either "for" belongs in both sentences, or neither one. Which is it?
Sounds good: You can attend for three weeks.
Sounds good: You can attend sessions for three weeks.
Sounds good: You can attend three sessions. (Sessions is not a period of time, it's an ordinary noun.)
Sounds awkward: You can attend three weeks.
"For" is what makes the periods of time sound natural.
This is usually the way we write:
The show lasted for three seasons.
Jane attended Stanford for two semesters.
Jane attended Stanford for three years.
The presidency lasted for eight years.
The presidency stretched for eight years.
I waited for 20 minutes.
Depending on the level of formality, you can speak without it, sometimes:
- The show lasted three seasons.
Jane attended Stanford two semesters. (sounds awkward)
Jane attended Stanford three years. (sounds awkward)
- The presidency lasted eight years.
- The presidency stretched eight years.
- I waited 20 minutes.
This usage is idiomatic and you can learn when this sounds okay --- see the other answers cited above --- but in written English, "for + a length of time" almost always sounds the most natural.