It's not described why AP4/ST4 is a special case, but supposing you try to group withing 3 sequential elements in ST for each (sp,ap):
SQL> with t (SP, AP, ST) as (
2 select 'SP1','AP1','ST1' from dual union all
3 select 'SP1','AP1','ST2' from dual union all
4 select 'SP1','AP1','ST3' from dual union all
5 select 'SP1','AP2','ST1' from dual union all
6 select 'SP1','AP2','ST2' from dual union all
7 select 'SP1','AP2','ST3' from dual union all
8 select 'SP1','AP3','ST1' from dual union all
9 select 'SP1','AP3','ST2' from dual union all
10 select 'SP1','AP4','ST1' from dual union all
11 select 'SP1','AP4','ST2' from dual union all
12 select 'SP1','AP4','ST3' from dual union all
13 select 'SP1','AP4','ST4' from dual
14 )
15 select sp, listagg(ap,',') within group (order by ap) lstap, lstst
16 from (
17 select sp, ap, listagg(st,',') within group (order by st) lstst from (
18 select sp, ap, st, ceil((row_number() over(partition by sp, ap order by st))/3) grp
19 from t
20 )
21 group by sp, ap, grp
22 )
23 group by sp, lstst
24 order by 1,2,3
25 /
SP LSTAP LSTST
--- ------------------------- -------------------------
SP1 AP1,AP2,AP4 ST1,ST2,ST3
SP1 AP3 ST1,ST2
SP1 AP4 ST4
P.S. For alternative result output:
SQL> with t (SP, AP, ST) as (
2 select 'SP1','AP1','ST1' from dual union all
3 select 'SP1','AP1','ST2' from dual union all
4 select 'SP1','AP1','ST3' from dual union all
5 select 'SP1','AP2','ST1' from dual union all
6 select 'SP1','AP2','ST2' from dual union all
7 select 'SP1','AP2','ST3' from dual union all
8 select 'SP1','AP3','ST1' from dual union all
9 select 'SP1','AP3','ST2' from dual union all
10 select 'SP1','AP4','ST1' from dual union all
11 select 'SP1','AP4','ST2' from dual union all
12 select 'SP1','AP4','ST3' from dual union all
13 select 'SP1','AP4','ST4' from dual
14 )
15 select sp, listagg(ap,',') within group (order by ap) lstap, lstst
16 from (
17 select sp, ap, listagg(st,',') within group (order by st) lstst from (
18 select sp, ap, st
19 from t
20 )
21 group by sp, ap
22 )
23 group by sp, lstst
24 order by 1,2,3
25 /
SP LSTAP LSTST
--- ------------------------- -------------------------
SP1 AP1,AP2 ST1,ST2,ST3
SP1 AP3 ST1,ST2
SP1 AP4 ST1,ST2,ST3,ST4