Используйте ROW_NUMBER()
в каждом запросе, чтобы создать общий столбец, к которому вы будете присоединяться:
select
t2.periodo_str, t2.fondo, t2.periodo, t1.afp, t1.fecha
from (
select t.*, row_number() over (order by t.fecha) rn
from (
select afp,
max(fecha) as fecha
from valcuota
where afp ='MODELO'
UNION
select afp,
date(max(fecha),'-31 days') as fecha
from valcuota
where afp ='MODELO'
) t
) t1 inner join (
select t.*, row_number() over (order by t.periodo) rn
from (
select strftime('%m-%Y',periodo) as periodo_str, fondo,periodo
from (
select fondo, periodo
from movimientos
group by fondo, periodo
order by count(periodo) desc
) temp where temp.fondo = fondo
group by periodo_str
order by periodo desc
limit 2
) t
) t2 on t2.rn = t1.rn