While there might be some user cases where carefully crafted experiences might allow this behavior, speaking of general available scripts, I wouldn't recommend it.
As an user, I want to know the available controls serve to a purpose (see locus of control) and you as a developer won't allow for random unexpected behaviors.
I'll give you an example: I click on some expandable element, and then scroll down to see the underlying content in context . If you close the lightbox, I'll be really annoyed. Simply put, you'd be willfully providing a bad experience that invalidates my intentionality. And even worse, you'd be doing it on purpose!
As for your examples:
On Medium website lightbox can be closed when user scrolls down, you
can test it here.
This is not a lightbox by any means, they're telling a story and allow a behavior of enlarging a photo. They have no controls whatsoever, so by continuing the story, you get to the original version
Some lightbox scripts, for example PhotoSwipe, close on scroll.
Tested it on FF, couldn't see this behavior. However, barring testing and some nice UX study, you could do this as long as is pictures only content
In short: never negate control to users, never do anything random or unexpected, always strive for simple experiences most users know
Additional Reading: