Additionally to my answer here, I may suggest the following workflow with less work with "Virtual Layer".
Let's assume there are two point layers
"end"(dark green), and one polygon layer
"poly"(blue) with its corresponding attribute tables accordingly, see image below.
Step 1. Deploy a "Virtual Layer" through
Layer > Add Layer > Add/Edit Virtual Layer... with the following query to create all possible lines connected between two points layers.
SELECT "poi".id AS pfrom,"end".id AS pto,
make_line("poi".geometry, "end".geometry) AS geom
FROM "poi", "end"
As an alternative to create all possible connections between points from two layesr you may try using the solution provided in this answer.
Step 2. Proceed with
"Extract by location" with ticked
within geometric predicate.
Note that the algorithm will be applied for lines that are entirely within each single polygon, i.e. no connections with points from neighbor polygons, see image below.
Step 3. Use
"Extract by expression"with the following expression
$length = minimum($length, "pfrom"). Afterwards the application of
"Join attributes by location" might be relevant.