Sometimes optional, sometimes necessary.
(a) When 了le is optional
When 没有 is used to ask the affirmative–negative question, 了 is optional if the verb has two characters or has an object following it.
你吃饭(了)没有?(= 你吃饭了吗?)
Nǐ chī fàn (le )méi yǒu?(= Nǐ chī fàn le ma?)
Have you eaten?
你爸爸退休(了)没有?(= 你爸爸退休了吗?) (退休 is a disyllabic verb.)
Nǐ bà bà tuì xiū (le) méi yǒu?(= Nǐ bà bà tuì xiū le ma?)
Has your father retired?
(b) When 了le is necessary
了 is necessary if the verb is monosyllabic and does not have an object following it.
小李做的菜,你吃了没有?(= 小李做的菜,你吃了吗?)
Xiǎo lǐ zuò de cài ,nǐ chī le méi yǒu?(= Xiǎo lǐ zuò de cài ,nǐ chī le ma?)
Have you eaten the food Xiao Li made?
(Do not say 小李做的菜,你吃没有? since the object of 吃 has been pre-posed.)
[1] Yip, P. C., Rimmington, D., Xiaoming, Z., & Henson, R. (2009). Basic Chinese: a grammar and workbook. Taylor & Francis.